optimize code

This forum is for eXpress++ general support.
Post Reply
Message
Author
Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

optimize code

#1 Post by Zdeno Bielik »

Hi Roger,

here is part from one my complex dialog screen, which works ok,
but I want/need make it „dynamic and generic“, little optimize also and use only locals variables(if it is possible)...

Code: Select all

Local nDospely  := 0
Local nStudent  := 0
*
Local nCL_Dospely   := 0
Local nCL_Student   := 0 
*
Local bS_L_Dospely  := { || nCL_Dospely  }
Local bS_L_Student  := { || nCL_Student  }
*
Local bS_CL_Dospely  := { || ( nDospely  * nCL_Dospely  ) }
Local bS_CL_Student  := { || ( nStudent  * nCL_Student  ) }


* variables are filled later by functions, codeblocks and/or users/operators via DCGET...


nRow++

@ nRow, 1 DCSAY 'Dospelý - F1' SAYSIZE 14   SAYID 'SAY_DOSPELY' SAYRIGHT  PARENT oSt_Vst
@ nRow,18 DCGET nDospely  PICTURE '99' GETID 'GET_DOSPELY' /*GETOBJECT oDospely*/ RANGE 0,99 ;
                VALID { || TestKV( ( nDospely + nStudent + nDochodca + nZajazd + nDieta + nDieta + nVolna ), nVolne ) } ;
                WHEN { || _lNova .and. ! M->plUzavrete .and. M->plSkupExist } ;
                LOSTFOCUS { || DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } ) } PARENT oSt_Vst
@ nRow,24 DCGET bS_L_Dospely WHEN { || .F. } PICT '999.99' GETSIZE 8,1.2 NOTABSTOP GETID obS_L_Dospely PARENT oSt_Vst
@ nRow,33 DCGET bS_CL_Dospely EDITPROTECT { || .T. } PICT '999.99' GETSIZE 8,1.2 NOTABSTOP COLOR GRA_CLR_BLUE, GRA_CLR_BACKGROUND ;
             LOSTFOCUS { || SetAppFocus( oDospely ) } PARENT oSt_Vst


nRow++

@ nRow, 1 DCSAY 'Študent - F2' SAYSIZE 14   SAYID 'SAY_STUDENT' SAYRIGHT PARENT oSt_Vst
@ nRow,18 DCGET nStudent  PICTURE '99' GETID 'GET_STUDENT' /*GETOBJECT oStudent*/ RANGE 0,99 ;
                VALID { || TestKV( ( nDospely + nStudent + nDochodca + nZajazd + nDieta + nVolna ), nVolne ) } ;
                WHEN { || _lNova .and. ! M->plUzavrete .and. M->plSkupExist } ;
                LOSTFOCUS { || DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } ) } PARENT oSt_Vst
@ nRow,24 DCGET bS_L_Student  WHEN { || .F. } PICT '999.99' GETSIZE 8,1.2 PARENT oSt_Vst
@ nRow,33 DCGET bS_CL_Student EDITPROTECT { || .T. } PICT '999.99' GETSIZE 8,1.2 NOTABSTOP COLOR GRA_CLR_BLUE, GRA_CLR_BACKGROUND ;
             LOSTFOCUS { || SetAppFocus( oStudent ) } PARENT oSt_Vst





  DCHOTKEY xbeK_F1 ;
          ACTION {|o| IIf( ! M->plUzavrete .and. M->plSkupExist, ;
                           ( o := DC_GetObject(GetList,'GET_DOSPELY'), ;
                             IIf( ( nDospely <= 98 ), nDospely++, NIL ), o:setData(), ;
                             DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } ), ;
                             SetAppFocus( o ) ), ;
                           NIL ) }

   DCHOTKEY xbeK_CTRL_F1 ;
          ACTION {|o| IIf( ! M->plUzavrete .and. M->plSkupExist, ;
                           ( o := DC_GetObject(GetList,'GET_DOSPELY'), ;
                             IIf( ( nDospely >= 1 ), nDospely--, NIL ), o:setData(), ;
                             DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } ), ;
                             SetAppFocus( o )), ;
                           NIL ) }



   DCHOTKEY xbeK_F2 ;
          ACTION {|o| IIf( ! M->plUzavrete .and. M->plSkupExist, ;
                           ( o := DC_GetObject(GetList,'GET_STUDENT'), ;
                             IIf( ( nStudent <= 98 ), nStudent++, NIL ), o:setData(), ;
                             DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } ), ;
                             SetAppFocus( o ) ), ;
                           NIL ) }

   DCHOTKEY xbeK_CTRL_F2 ;
          ACTION {|o| IIf( ! M->plUzavrete .and. M->plSkupExist, ;
                           ( o := DC_GetObject(GetList,'GET_STUDENT'), ;
                             IIf( ( nStudent >= 1 ), nStudent--, NIL ), o:setData(), ;
                             DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } ), ;
                             SetAppFocus( o ) ), ;
                            NIL ) }


As reference I use your Invoice.prg from directory samples, where I started make some changes, but I cannot make it like I need...
I want only allow edit Quantity field and in added column Sum I want show summary Quantity and Price
Also I want change value in Get with Fn or Ctrl_Fn keys and refresh Sum column

Differences with your code (Added/Removed parts) are marked.

Code: Select all

/*
This is a generic Invoice Form designed for printing with
the DCPRINT system.  All invoice data is passed to the
function PrintInvoice() in a multi-dimensional array.
*/

#INCLUDE "dcprint.ch"
#INCLUDE "dcdialog.ch"
#INCLUDE "common.CH"

#include "APPEVENT.CH"                     && added

#define INVOICE_LOGO               1

#define INVOICE_FROM_NAME          2
#define INVOICE_FROM_ADDR1         3
#define INVOICE_FROM_ADDR2         4
#define INVOICE_FROM_CITY          5
#define INVOICE_FROM_STATE         6
#define INVOICE_FROM_ZIP           7
#define INVOICE_FROM_COUNTRY       8
#define INVOICE_FROM_TAXID         9
#define INVOICE_FROM_PHONE         10
#define INVOICE_FROM_FAX           11
#define INVOICE_FROM_EMAIL         12

#define INVOICE_REMIT_NAME         13
#define INVOICE_REMIT_ADDR1        14
#define INVOICE_REMIT_ADDR2        15
#define INVOICE_REMIT_CITY         16
#define INVOICE_REMIT_STATE        17
#define INVOICE_REMIT_ZIP          18
#define INVOICE_REMIT_COUNTRY      19

#define INVOICE_ACCT_NO            20

#define INVOICE_BILL_NAME          21
#define INVOICE_BILL_ADDR1         22
#define INVOICE_BILL_ADDR2         23
#define INVOICE_BILL_CITY          24
#define INVOICE_BILL_STATE         25
#define INVOICE_BILL_ZIP           26
#define INVOICE_BILL_COUNTRY       27
#define INVOICE_BILL_CONTACT       28

#define INVOICE_SHIP_NAME          29
#define INVOICE_SHIP_ADDR1         30
#define INVOICE_SHIP_ADDR2         31
#define INVOICE_SHIP_CITY          32
#define INVOICE_SHIP_STATE         33
#define INVOICE_SHIP_ZIP           34
#define INVOICE_SHIP_COUNTRY       35
#define INVOICE_SHIP_PHONE         36
#define INVOICE_SHIP_FAX           37
#define INVOICE_SHIP_EMAIL         38
#define INVOICE_SHIP_CONTACT       39

#define INVOICE_NUMBER             40
#define INVOICE_DATE               41
#define INVOICE_SALESMAN           42
#define INVOICE_PO_NO              43
#define INVOICE_SO_NO              44
#define INVOICE_ORDER_DATE         45
#define INVOICE_SHIP_VIA           46
#define INVOICE_TERMS              47
#define INVOICE_SHIP_DATE          48
#define INVOICE_NONTAXABLE         49
#define INVOICE_TAXABLE            50
#define INVOICE_SALESTAX           51
#define INVOICE_FREIGHT            52
#define INVOICE_MISC               53
#define INVOICE_TOTAL              54
#define INVOICE_COMMENTS           55
#define INVOICE_TAXRATE            56

#define INVOICE_ITEMS              57

#define INVOICE_ARRAY_SIZE         57


#define INVOICE_ITEM_PARTNO         1
#define INVOICE_ITEM_DESC           2
#define INVOICE_ITEM_QTY_ORD        3
#define INVOICE_ITEM_QTY_SHIP       4
#define INVOICE_ITEM_QTY_BO         5
#define INVOICE_ITEM_UI             6
#define INVOICE_ITEM_UPRICE         7
#define INVOICE_ITEM_AMOUNT         8
#define INVOICE_ITEM_TAXABLE        9

#define INVOICE_ITEM_SUM           10    && Added
#define INVOICE_ITEM_HOTKEY        11    && Added
#define INVOICE_ITEM_HOTKEY_P      12    && Added
#define INVOICE_ITEM_HOTKEY_M      13    && Added

* #define INVOICE_ITEM_ARRAY_SIZE     9  && Removed
#define INVOICE_ITEM_ARRAY_SIZE    13    && Added



#define HOTKEYS_ITEM_1     1            && Added
#define HOTKEYS_ITEM_2     2            && Added
#define HOTKEYS_ITEM_3     3            && Added
#define HOTKEYS_ITEM_4     4            && Added
#define HOTKEYS_ITEM_5     5            && Added
#define HOTKEYS_ITEM_6     6            && Added
#define HOTKEYS_ITEM_7     7            && Added
#define HOTKEYS_ITEM_8     8            && Added
#define HOTKEYS_ITEM_9     9            && Added
#define HOTKEYS_ITEM_10   10            && Added
#define HOTKEYS_ITEM_11   11            && Added
#define HOTKEYS_ITEM_12   12            && Added

#define HOTKEYS_ITEM_ARRAY_SIZE    12    && Added



/*

Specifications for aData :

Element               Description
--------             -------------------------------------------------------------
INVOICE_LOGO           Logo ( resource, .JPG/.GIF file name, or XbpBitMap() object

INVOICE_FROM_NAME      From: Name
INVOICE_FROM_ADDR1     From: Address Line 1
INVOICE_FROM_ADDR2     From: Address Line 2
INVOICE_FROM_CITY      From: City
INVOICE_FROM_STATE     From: State
INVOICE_FROM_ZIP       From: Zip
INVOICE_FROM_COUNTRY   From: Country
INVOICE_FROM_TAXID     From: Tax ID
INVOICE_FROM_PHONE     From: Telephone
INVOICE_FROM_FAX       From: Fax
INVOICE_FROM_EMAIL     From: Email

INVOICE_REMIT_NAME     Remit to: Name
INVOICE_REMIT_ADDR1    Remit to: Address Line 1
INVOICE_REMIT_ADDR2    Remit to: Address Line 2
INVOICE_REMIT_CITY     Remit to: City
INVOICE_REMIT_STATE    Remit to: State
INVOICE_REMIT_ZIP      Remit to: Zip
INVOICE_REMIT_COUNTRY  Remit to: Country

INVOICE_ACCT_NO        Customer Account Number

INVOICE_BILL_NAME      Bill to: Name
INVOICE_BILL_ADDR1     Bill to: Address Line 1
INVOICE_BILL_ADDR2     Bill to: Address Line 2
INVOICE_BILL_CITY      Bill to: City
INVOICE_BILL_STATE     Bill to: State
INVOICE_BILL_ZIP       Bill to: Zip
INVOICE_BILL_COUNTRY   Bill to: Country
INVOICE_BILL_CONTACT   Bill to: Contact Person

INVOICE_SHIP_NAME      Ship to: Name
INVOICE_SHIP_ADDR1     Ship to: Address Line 1
INVOICE_SHIP_ADDR2     Ship to: Address Line 2
INVOICE_SHIP_CITY      Ship to: City
INVOICE_SHIP_STATE     Ship to: State
INVOICE_SHIP_ZIP       Ship to: Zip
INVOICE_SHIP_COUNTRY   Ship to: Country
INVOICE_SHIP_PHONE     Ship to: Phone
INVOICE_SHIP_FAX       Ship to: Fax
INVOICE_SHIP_EMAIL     Ship to: Email
INVOICE_SHIP_CONTACT   Ship to: Contact Person

INVOICE_NUMBER         Invoice Number
INVOICE_DATE           Invoice Date
INVOICE_SALESMAN       Salesman
INVOICE_PO_NO          Purchase Order Number
INVOICE_SO_NO          Sales Order Number
INVOICE_ORDER_DATE     Order Date
INVOICE_SHIP_VIA       Shipped Via
INVOICE_TERMS          Terms
INVOICE_SHIP_DATE      Ship Date
INVOICE_NONTAXABLE     Non-Taxable Total
INVOICE_TAXABLE        Taxable Total
INVOICE_SALESTAX       Sales Tax Total
INVOICE_FREIGHT        Freight Total
INVOICE_MISC           Misc Total
INVOICE_TOTAL          Invoice Total
INVOICE_COMMENTS       Comments
INVOICE_TAXRATE        Sales Tax Rate

INVOICE_ITEMS          Line Items sub array (see separate specification)


Specifications for Line Items array :

Element                Description
--------              ------------------------------------------------------------
INVOICE_ITEM_PARTNO    Part Number
INVOICE_ITEM_DESC      Description
INVOICE_ITEM_QTY_ORD   Quantity Ordered
INVOICE_ITEM_QTY_SHIP  Quantity Shipped
INVOICE_ITEM_QTY_BO    Quantity Backordered
INVOICE_ITEM_UI        Unit of Issue
INVOICE_ITEM_UPRICE    Unit Price
INVOICE_ITEM_AMOUNT    Amount

*/

MEMVAR aInvoice

FUNCTION Main()

LOCAL i, GetList[0], aData[INVOICE_ARRAY_SIZE], aItems[10], GetOptions, ;
      nRow, nCol, oTabPage1, oTabPage2, oTabPage3, oTabPage4, lStatus, ;
      cAcrobatVersion, aAcrobat, cPDFDriver, ;
      aHotKeys[HOTKEYS_ITEM_ARRAY_SIZE], ;                           && added
      cValid, bValid, ;                                              && added
      nHotKeyK_P, nHotKeyK_M, ;                                      && added
      cHotKeyK_P, bHotKeyK_P, cHotKeyK_M, bHotKeyK_M                 && added


aHotKeys[HOTKEYS_ITEM_1]  := { 'F1' , xbeK_F1 , xbeK_CTRL_F1  }      && added
aHotKeys[HOTKEYS_ITEM_2]  := { 'F2' , xbeK_F2 , xbeK_CTRL_F2  }      && added
aHotKeys[HOTKEYS_ITEM_3]  := { 'F3' , xbeK_F3 , xbeK_CTRL_F3  }      && added
aHotKeys[HOTKEYS_ITEM_4]  := { 'F4' , xbeK_F4 , xbeK_CTRL_F4  }      && added
aHotKeys[HOTKEYS_ITEM_5]  := { 'F5' , xbeK_F5 , xbeK_CTRL_F5  }      && added
aHotKeys[HOTKEYS_ITEM_6]  := { 'F6' , xbeK_F6 , xbeK_CTRL_F6  }      && added
aHotKeys[HOTKEYS_ITEM_7]  := { 'F7' , xbeK_F7 , xbeK_CTRL_F7  }      && added
aHotKeys[HOTKEYS_ITEM_8]  := { 'F8' , xbeK_F8 , xbeK_CTRL_F8  }      && added
aHotKeys[HOTKEYS_ITEM_9]  := { 'F9' , xbeK_F9 , xbeK_CTRL_F9  }      && added
aHotKeys[HOTKEYS_ITEM_10] := { 'F10', xbeK_F10, xbeK_CTRL_F10 }      && added
aHotKeys[HOTKEYS_ITEM_11] := { 'F11', xbeK_F11, xbeK_CTRL_F11 }      && added
aHotKeys[HOTKEYS_ITEM_12] := { 'F12', xbeK_F12, xbeK_CTRL_F12 }      && added


cAcrobatVersion := GetEnv('ACROBAT_VERSION')
IF Empty(cAcrobatVersion)
  cAcrobatVersion := '5'
ENDIF

IF AScan(XbpPrinter():new():list(),{|c|Upper(c)=='BULLZIP PDF PRINTER'}) > 0
  cPDFDriver := 'Bullzip PDF Printer'
ELSE
  cPDFDriver := 'Win2PDF'
ENDIF

DC_GroupBoxFix(.t.)

aAcrobat := DC_PrintPreviewAcrobatOpt()
aAcrobat[1] := 1 // Modal
aAcrobat[2] := AppDeskTop() // Parent
aAcrobat[3] := cAcrobatVersion
aAcrobat[6] := .T. // Ok/Cancel buttons
aAcrobat[7] := cPDFDriver
// aAcrobat[8] := 3 // Use Runshell to Call Acrobat
aAcrobat[8] := 3 // Use Acrobat ActiveX control to Call Acrobat

DC_PrintPreviewAcrobatOpt(aAcrobat)


* IF File('INVOICE.XPF')      && removed
IF .t. == .f.                 && added


  PRIVATE aInvoice
  RESTORE FROM INVOICE.XPF
  aData := M->aInvoice
  aItems := M->aInvoice[INVOICE_ITEMS]

ELSE

  aData[INVOICE_LOGO]          := Pad('DONNAY.JPG',40)
  aData[INVOICE_FROM_NAME]     := Pad('Donnay Software Designs',40)
  aData[INVOICE_FROM_ADDR1]    := Pad('1632 Riverstone Ln #301',40)
  aData[INVOICE_FROM_ADDR2]    := Space(40)
  aData[INVOICE_FROM_CITY]     := Pad('Boise',30)
  aData[INVOICE_FROM_STATE]    := Pad('ID',15)
  aData[INVOICE_FROM_ZIP]      := Pad('83706',10)
  aData[INVOICE_FROM_COUNTRY]  := Pad('U.S.A.',20)
  aData[INVOICE_FROM_TAXID]    := Pad('33-567982',15)
  aData[INVOICE_FROM_PHONE]    := Pad('208-331-2516',15)
  aData[INVOICE_FROM_FAX]      := Pad('208-331-2621',15)
  aData[INVOICE_FROM_EMAIL]    := Pad('acctsrec@donnay-software.com',40)

  aData[INVOICE_REMIT_NAME]    := aData[INVOICE_FROM_NAME]
  aData[INVOICE_REMIT_ADDR1]   := aData[INVOICE_FROM_ADDR1]
  aData[INVOICE_REMIT_ADDR2]   := aData[INVOICE_FROM_ADDR2]
  aData[INVOICE_REMIT_CITY]    := aData[INVOICE_FROM_CITY]
  aData[INVOICE_REMIT_STATE]   := aData[INVOICE_FROM_STATE]
  aData[INVOICE_REMIT_ZIP]     := aData[INVOICE_FROM_ZIP]
  aData[INVOICE_REMIT_COUNTRY] := aData[INVOICE_FROM_COUNTRY]

  aData[INVOICE_ACCT_NO] := Space(10)

  aData[INVOICE_BILL_NAME]    := Space(40)
  aData[INVOICE_BILL_ADDR1]   := Space(40)
  aData[INVOICE_BILL_ADDR2]   := Space(40)
  aData[INVOICE_BILL_CITY]    := Space(30)
  aData[INVOICE_BILL_STATE]   := Space(15)
  aData[INVOICE_BILL_ZIP]     := Space(10)
  aData[INVOICE_BILL_COUNTRY] := Space(20)
  aData[INVOICE_BILL_CONTACT] := Space(30)

  aData[INVOICE_SHIP_NAME]    := Space(40)
  aData[INVOICE_SHIP_ADDR1]   := Space(40)
  aData[INVOICE_SHIP_ADDR2]   := Space(40)
  aData[INVOICE_SHIP_CITY]    := Space(30)
  aData[INVOICE_SHIP_STATE]   := Space(15)
  aData[INVOICE_SHIP_ZIP]     := Space(10)
  aData[INVOICE_SHIP_COUNTRY] := Space(20)
  aData[INVOICE_SHIP_PHONE]   := Space(25)
  aData[INVOICE_SHIP_FAX]     := Space(25)
  aData[INVOICE_SHIP_EMAIL]   := Space(40)
  aData[INVOICE_SHIP_CONTACT] := Space(30)

  aData[INVOICE_NUMBER]       := Space(10)
  aData[INVOICE_DATE]         := Date()
  aData[INVOICE_SALESMAN]     := Pad('RDONNAY',10)
  aData[INVOICE_PO_NO]        := Space(10)
  aData[INVOICE_SO_NO]        := Space(10)
  aData[INVOICE_ORDER_DATE]   := Date()-10
  aData[INVOICE_SHIP_VIA]     := Pad('FedEx 2-Day',15)
  aData[INVOICE_TERMS]        := Pad('Net-30',15)
  aData[INVOICE_SHIP_DATE]    := Date()
  aData[INVOICE_NONTAXABLE]   := 0
  aData[INVOICE_TAXABLE]      := 0
  aData[INVOICE_SALESTAX]     := 0
  aData[INVOICE_FREIGHT]      := 0
  aData[INVOICE_MISC]         := 0
  aData[INVOICE_TOTAL]        := 0
  aData[INVOICE_COMMENTS]     := ''
  aData[INVOICE_TAXRATE]      := 0

  FOR i := 1 TO Len(aItems)
    aItems[i] := Array(INVOICE_ITEM_ARRAY_SIZE)
*     aItems[i,INVOICE_ITEM_PARTNO]     := Space(15)               && removed
    aItems[i,INVOICE_ITEM_PARTNO]     := ( 'item-' + AS( i ) )     && added
    aItems[i,INVOICE_ITEM_DESC]       := Space(50)
    aItems[i,INVOICE_ITEM_QTY_ORD]    := 0
    aItems[i,INVOICE_ITEM_QTY_SHIP]   := 0
    aItems[i,INVOICE_ITEM_QTY_BO]     := 0
    aItems[i,INVOICE_ITEM_UI]         := 'EA      '
*     aItems[i,INVOICE_ITEM_UPRICE]     := 0     && removed
    aItems[i,INVOICE_ITEM_UPRICE]     := i       && Added
    aItems[i,INVOICE_ITEM_AMOUNT]     := 0
    aItems[i,INVOICE_ITEM_TAXABLE]    := .t.
    aItems[i,INVOICE_ITEM_SUM]        := 0                   && Added
    aItems[i,INVOICE_ITEM_HOTKEY]     := aHotKeys[i,1]       && Added
    aItems[i,INVOICE_ITEM_HOTKEY_P]   := aHotKeys[i,2]       && Added
    aItems[i,INVOICE_ITEM_HOTKEY_M]   := aHotKeys[i,3]       && Added
  NEXT
  wtf aItems                                     && Added

ENDIF


* @ 0,0 DCTABPAGE oTabPage1 CAPTION 'General' SIZE 93,24 ;    && removed
@ 0,0 DCTABPAGE oTabPage1 CAPTION 'General' SIZE 120,24 ;     && added
      GOTFOCUS {||UpdateTotals(aData,aItems),DC_GetRefresh(GetList)}

@ 0,0 DCTABPAGE oTabPage2 CAPTION 'From' RELATIVE oTabPage1

@ 0,0 DCTABPAGE oTabPage3 CAPTION 'To' RELATIVE oTabPage2

@ 0,0 DCTABPAGE oTabPage4 CAPTION 'Items' RELATIVE oTabPage3

DCSETPARENT TO oTabPage1

nRow := 2
nCol := 2

@ nRow++,nCol DCSAY 'Invoice Number' GET aData[INVOICE_NUMBER]
@ nRow++,nCol DCSAY 'Date' GET aData[INVOICE_DATE] POPUP {|d|DC_PopDate(d)}
@ nRow++,nCol DCSAY 'Salesman' GET aData[INVOICE_SALESMAN]
@ nRow++,nCol DCSAY 'P.O. Number' GET aData[INVOICE_PO_NO]
@ nRow++,nCol DCSAY 'S.O. Number' GET aData[INVOICE_SO_NO]
@ nRow++,nCol DCSAY 'Order Date' GET aData[INVOICE_ORDER_DATE] POPUP {|d|DC_PopDate(d)}
@ nRow++,nCol DCSAY 'Shipped Via' GET aData[INVOICE_SHIP_VIA]
@ nRow++,nCol DCSAY 'Terms' GET aData[INVOICE_TERMS]
@ nRow++,nCol DCSAY 'Ship Date' GET aData[INVOICE_SHIP_DATE] POPUP {|d|DC_PopDate(d)}
@ nRow++,nCol DCSAY 'Non-Taxable' GET aData[INVOICE_NONTAXABLE] PICT '999999.99' WHEN {||.f.}
@ nRow++,nCol DCSAY 'Taxable' GET aData[INVOICE_TAXABLE] PICT '999999.99' WHEN {||.f.}
@ nRow++,nCol DCSAY 'Tax Rate' GET aData[INVOICE_TAXRATE] PICT '9.9999'
@ nRow++,nCol DCSAY 'Sales Tax' GET aData[INVOICE_SALESTAX] PICT '999999.99' WHEN {||.f.}
@ nRow++,nCol DCSAY 'Freight' GET aData[INVOICE_FREIGHT] PICT '999999.99'
@ nRow++,nCol DCSAY 'Misc Amount' GET aData[INVOICE_MISC] PICT '999999.99'
@ nRow++,nCol DCSAY 'Total Amount' GET aData[INVOICE_TOTAL] PICT '999999.99' WHEN {||.f.}

@ nRow++,nCol DCSAY 'Comments' COLOR GRA_CLR_BLUE FONT '10.Courier Bold'
@ nRow++,nCol DCMULTILINE aData[INVOICE_COMMENTS] SIZE 80,4 FONT '8.Courier'

DCSETPARENT TO oTabPage2

nRow := 2

@ nRow++,nCol DCSAY 'Logo File' GET aData[INVOICE_LOGO] POPUP {|c|DC_PopFile(c)}
@ nRow++,nCol DCSAY 'Name' GET aData[INVOICE_FROM_NAME]
@ nRow++,nCol DCSAY 'Address 1' GET aData[INVOICE_FROM_ADDR1]
@ nRow++,nCol DCSAY 'Address 2' GET aData[INVOICE_FROM_ADDR2]
@ nRow++,nCol DCSAY 'City' GET aData[INVOICE_FROM_CITY]
@ nRow++,nCol DCSAY 'State' GET aData[INVOICE_FROM_STATE]
@ nRow++,nCol DCSAY 'Zip' GET aData[INVOICE_FROM_ZIP]
@ nRow++,nCol DCSAY 'Country' GET aData[INVOICE_FROM_COUNTRY]
@ nRow++,nCol DCSAY 'Tax ID' GET aData[INVOICE_FROM_TAXID]
@ nRow++,nCol DCSAY 'Phone' GET aData[INVOICE_FROM_PHONE]
@ nRow++,nCol DCSAY 'Fax' GET aData[INVOICE_FROM_FAX]
@ nRow++,nCol DCSAY 'E-Mail' GET aData[INVOICE_FROM_EMAIL]

nRow++

@ nRow++,nCol+2 DCSAY 'Remit to:' SAYLEFT COLOR GRA_CLR_BLUE FONT '10.Courier'
@ nRow++,nCol DCSAY 'Name' GET aData[INVOICE_REMIT_NAME]
@ nRow++,nCol DCSAY 'Address 1' GET aData[INVOICE_REMIT_ADDR1]
@ nRow++,nCol DCSAY 'Address 2' GET aData[INVOICE_REMIT_ADDR2]
@ nRow++,nCol DCSAY 'City' GET aData[INVOICE_REMIT_CITY]
@ nRow++,nCol DCSAY 'State' GET aData[INVOICE_REMIT_STATE]
@ nRow++,nCol DCSAY 'Zip' GET aData[INVOICE_REMIT_ZIP]
@ nRow++,nCol DCSAY 'Country' GET aData[INVOICE_REMIT_COUNTRY]

DCSETPARENT TO oTabPage3

nRow := 2

@ nRow++,nCol+2 DCSAY 'Bill to:' COLOR GRA_CLR_BLUE FONT '10.Courier'
@ nRow++,nCol DCSAY 'Name' GET aData[INVOICE_BILL_NAME]
@ nRow++,nCol DCSAY 'Address 1' GET aData[INVOICE_BILL_ADDR1]
@ nRow++,nCol DCSAY 'Address 2' GET aData[INVOICE_BILL_ADDR2]
@ nRow++,nCol DCSAY 'City' GET aData[INVOICE_BILL_CITY]
@ nRow++,nCol DCSAY 'State' GET aData[INVOICE_BILL_STATE]
@ nRow++,nCol DCSAY 'Zip' GET aData[INVOICE_BILL_ZIP]
@ nRow++,nCol DCSAY 'Country' GET aData[INVOICE_BILL_COUNTRY]
@ nRow++,nCol DCSAY 'Contact' GET aData[INVOICE_BILL_CONTACT]

nRow++
@ nRow++,nCol+2 DCSAY 'Ship to:' COLOR GRA_CLR_BLUE FONT '10.Courier'
@ nRow++,nCol DCSAY 'Name' GET aData[INVOICE_SHIP_NAME]
@ nRow++,nCol DCSAY 'Address 1' GET aData[INVOICE_SHIP_ADDR1]
@ nRow++,nCol DCSAY 'Address 2' GET aData[INVOICE_SHIP_ADDR2]
@ nRow++,nCol DCSAY 'City' GET aData[INVOICE_SHIP_CITY]
@ nRow++,nCol DCSAY 'State' GET aData[INVOICE_SHIP_STATE]
@ nRow++,nCol DCSAY 'Zip' GET aData[INVOICE_SHIP_ZIP]
@ nRow++,nCol DCSAY 'Country' GET aData[INVOICE_SHIP_COUNTRY]
@ nRow++,nCol DCSAY 'Phone' GET aData[INVOICE_SHIP_PHONE]
@ nRow++,nCol DCSAY 'Fax' GET aData[INVOICE_SHIP_FAX]
@ nRow++,nCol DCSAY 'Contact' GET aData[INVOICE_SHIP_CONTACT]

DCSETPARENT TO oTabPage4

nRow := 2

@ nRow, 2 DCSAY 'Part Number' SAYSIZE 0 COLOR GRA_CLR_BLUE FONT '10.Helv'
@ nRow, 20 DCSAY 'Description' SAYSIZE 0 COLOR GRA_CLR_BLUE FONT '10.Helv'
@ nRow, 50 DCSAY 'Qty' SAYSIZE 0 COLOR GRA_CLR_BLUE FONT '10.Helv'
@ nRow, 56 DCSAY 'Qty' SAYSIZE 0 COLOR GRA_CLR_BLUE FONT '10.Helv'
@ nRow, 62 DCSAY 'Qty' SAYSIZE 0 COLOR GRA_CLR_BLUE FONT '10.Helv'
@ nRow, 68 DCSAY 'U/I' SAYSIZE 0 COLOR GRA_CLR_BLUE FONT '10.Helv'
@ nRow, 76 DCSAY 'U/Price' SAYSIZE 0 COLOR GRA_CLR_BLUE FONT '10.Helv'
@ nRow, 87 DCSAY 'Tax' SAYSIZE 0 COLOR GRA_CLR_BLUE FONT '10.Helv'
nRow++
@ nRow, 50 DCSAY 'Ord' SAYSIZE 0 COLOR GRA_CLR_BLUE FONT '10.Helv'
@ nRow, 56 DCSAY 'Ship' SAYSIZE 0 COLOR GRA_CLR_BLUE FONT '10.Helv'
@ nRow, 62 DCSAY 'B/O' SAYSIZE 0 COLOR GRA_CLR_BLUE FONT '10.Helv'
nRow++

FOR i := 1 TO Len(aItems)
  nRow++
  @ nRow,2 DCGET aItems[i,INVOICE_ITEM_PARTNO] ;
           WHEN {|| .f. }                                        && added
  @ nRow,20 DCGET aItems[i,INVOICE_ITEM_DESC] SIZE 30 ;
           WHEN {|| .f. }                                        && added

  cValid := '{ || aItems[' + AS( i ) + ',INVOICE_ITEM_SUM] := ( aItems[' + AS( i ) + ',INVOICE_ITEM_QTY_ORD] * aItems[' + AS( i ) + ',INVOICE_ITEM_UPRICE] ), dc_qout(aItems) }'     && added
  bValid := &( cValid )                                                                                              && added
  wtf cValid

  cGetID := ( 'GET_F' + AS( i ) )    && added

* hmmm, when I un-remark bValid, in runtime it says that aItems is not declared...

  @ nRow,50 DCGET aItems[i,INVOICE_ITEM_QTY_ORD] PICT '9999' ;
            ; && VALID bValid ;                                       && added
            GETID cGetID                                         && added


  @ nRow,56 DCGET aItems[i,INVOICE_ITEM_QTY_SHIP] PICT '9999' ;
           WHEN {|| .f. }                                        && added
  @ nRow,62 DCGET aItems[i,INVOICE_ITEM_QTY_BO] PICT '9999' ;
           WHEN {|| .f. }                                        && added
  @ nRow,68 DCGET aItems[i,INVOICE_ITEM_UI] GETSIZE 7 ;
           WHEN {|| .f. }                                        && added
  @ nRow,76 DCGET aItems[i,INVOICE_ITEM_UPRICE] PICT '99999.99' ;
           WHEN {|| .f. }                                        && added
  @ nRow,88 DCCHECKBOX aItems[i,INVOICE_ITEM_TAXABLE] ;
           WHEN {|| .f. }                                        && added
  @ nRow,94 DCGET aItems[i,INVOICE_ITEM_SUM] PICT '99999.99' ;   && added
           WHEN {|| .f. }                                        && added
  @ nRow,105 DCGET aItems[i,INVOICE_ITEM_HOTKEY]  ;              && added
           WHEN {|| .f. }                                        && added


   nHotKeyK_P := aItems[i,INVOICE_ITEM_HOTKEY_P]                 && added
   nHotKeyK_M := aItems[i,INVOICE_ITEM_HOTKEY_M]                 && added
   wtf nHotKeyK_P, nHotKeyK_M

   cHotKeyK_P := '{ || MsgBox("plus-' + AS( i ) + '") }'         && added
*    cHotKeyK_P := '{ || MsgBox("plus-' + 'aItems[' + AS( i ) + ',INVOICE_ITEM_SUM]' + '") }'         && added
*    cHotKeyK_P := '{ |a| a:= aItems[' + AS( i ) + ',INVOICE_ITEM_HOTKEY]' + ', MsgBox("plus-"' + a + ') }'         && added
*    cHotKeyK_P := '{ |a| a:= aItems[' + AS( i ) + ',INVOICE_ITEM_HOTKEY] }'         && added
*    cHotKeyK_P := '{ |a| MsgBox( Var2Char( aItems[' + AS( i ) + ',INVOICE_ITEM_HOTKEY] ) ) }'         && added
   wtf cHotKeyK_P
*    cHotKeyK_P := '{ || MsgBox("plus-' + AS( i ) + '") }'         && added
   bHotKeyK_P := &( cHotKeyK_P )                                 && added
   cHotKeyK_M := '{ || MsgBox("minus-' + AS( i ) + '") }'        && added
   bHotKeyK_M := &( cHotKeyK_M )                                 && added
   wtf cHotKeyK_P, cHotKeyK_M

   DCHOTKEY nHotKeyK_P ACTION bHotKeyK_P                         && added
   DCHOTKEY nHotKeyK_M ACTION bHotKeyK_M                         && added

NEXT

DCSETPARENT TO

@ 25,1 DCPUSHBUTTON CAPTION 'Exit' SIZE 9,1.2 ;
       ACTION {||DC_ReadGuiEvent(DCGUI_EXIT_OK,GetList)}

@ 25,12 DCPUSHBUTTON CAPTION 'Print' SIZE 9,1.2 ;
       ACTION {||aData[INVOICE_ITEMS] := aItems, PrintInvoice(aData)}

@ 25,24 DCPUSHBUTTON CAPTION 'Email Setup' SIZE 12,1.2 ;
       ACTION {||EmailSetup()}

DCGETOPTIONS ;
   HILITEGETS GRA_CLR_RED ;
   SAYWIDTH 100 ;
   SAYRIGHT ;
   DISABLEDCOLOR GRA_CLR_WHITE

DCREAD GUI FIT OPTIONS GetOptions ;
   TITLE 'Create and Print an Invoice' ;
   TO lStatus SETAPPWINDOW ;
   EVAL { |o| wtf o, GetList }                  && added

IF lStatus
  UpdateTotals( aData, aItems )
  aInvoice := aData
  aInvoice[INVOICE_ITEMS] := aItems
  SAVE ALL LIKE aInvoice TO INVOICE.XPF
ENDIF

RETURN nil

* ----------------

STATIC FUNCTION UpdateTotals( aData, aItems )

LOCAL i, nTaxable := 0, nNonTaxable := 0, nSalesTax := 0

FOR i := 1 TO Len(aItems)
  aItems[i,INVOICE_ITEM_AMOUNT] := ;
     aItems[i,INVOICE_ITEM_QTY_SHIP] * aItems[i,INVOICE_ITEM_UPRICE]
  IF aItems[i,INVOICE_ITEM_TAXABLE]
    nTaxable += aItems[i,INVOICE_ITEM_AMOUNT]
    nSalesTax += aItems[i,INVOICE_ITEM_AMOUNT] * aData[INVOICE_TAXRATE]
  ELSE
    nNonTaxable += aItems[i,INVOICE_ITEM_AMOUNT]
  ENDIF
NEXT
aData[INVOICE_TAXABLE] := nTaxable
aData[INVOICE_NONTAXABLE] := nNonTaxable
aData[INVOICE_SALESTAX] := nSalesTax
aData[INVOICE_TOTAL] := nTaxable + nNonTaxable + nSalesTax + ;
     aData[INVOICE_FREIGHT] + aData[INVOICE_MISC]

RETURN nil

* ----------------

STATIC FUNCTION PrintInvoice( aData )

LOCAL oPrinter, nRow, nCol, nOffset, i, nLineCount, cComments, nHeight, ;
      nSaveRow, aItems, cMemoLine, aAcrobatOptions

IF !Print_Choice( 'Print Invoice', 1, 'rogerdonnay@donnay-software.com', FALSE )
  RETURN FALSE
ENDIF

IF !PrintOn('Invoice',@oPrinter)
  RETURN FALSE
ENDIF

nRow := 2

// Print Logo

@ nRow,4,nRow+7,20 DCPRINT BITMAP aData[INVOICE_LOGO] AUTOSCALE

// Print Invoice Number Box

@ nRow,60,nRow+7,77 DCPRINT BOX FILL 3 GRAY 10
@ nRow+2,60,nRow+2,77 DCPRINT LINE
@ nRow+.6,62 DCPRINT SAY 'INVOICE' FONT '22.Arial Bold'
@ nRow+2.1,62 DCPRINT SAY aData[INVOICE_NUMBER] FONT '14.Courier New Bold'
@ nRow+4,60,nRow+4,77 DCPRINT LINE
@ nRow+5,61 DCPRINT SAY 'Date:'
@ nRow+5,67 DCPRINT SAY DtoC(aData[INVOICE_DATE]) FONT '10.Courier New'

// Print Company Heading (Name and Address)

DCPRINT FONT '12.Arial Bold'

@ nRow++,40 DCPRINT SAY Trim(aData[INVOICE_FROM_NAME]) ALIGN DCPRINT_ALIGN_HCENTER

@ nRow++,40 DCPRINT SAY Trim(aData[INVOICE_FROM_ADDR1]) ALIGN DCPRINT_ALIGN_HCENTER

IF !Empty(aData[INVOICE_FROM_ADDR2])
  @ nRow++,40 DCPRINT SAY Trim(aData[INVOICE_FROM_ADDR1]) ALIGN DCPRINT_ALIGN_HCENTER
ENDIF

@ nRow++,40 DCPRINT SAY Trim(aData[INVOICE_FROM_CITY]) + ', ' + ;
                        Trim(aData[INVOICE_FROM_STATE]) + ' ' + ;
                        Trim(aData[INVOICE_FROM_ZIP]) ;
            ALIGN DCPRINT_ALIGN_HCENTER

@ nRow++,40 DCPRINT SAY Trim(aData[INVOICE_FROM_COUNTRY]) ;
            ALIGN DCPRINT_ALIGN_HCENTER

DCPRINT FONT '10.Arial'

@ nRow++,40 DCPRINT SAY 'Phone: ' + Trim(aData[INVOICE_FROM_PHONE]) ;
            ALIGN DCPRINT_ALIGN_HCENTER

@ nRow++,40 DCPRINT SAY 'Fax: ' + Trim(aData[INVOICE_FROM_FAX]) ;
            ALIGN DCPRINT_ALIGN_HCENTER

@ nRow++,40 DCPRINT SAY 'E-Mail: ' + Trim(aData[INVOICE_FROM_EMAIL]) ;
            ALIGN DCPRINT_ALIGN_HCENTER



nRow += 3

// Print Bill To and Ship To boxes

@ nRow,4, nRow+10,40 DCPRINT BOX GRAY 5
@ nRow+1.5,4, nRow+1.5,40 DCPRINT LINE
@ nRow,5 DCPRINT SAY 'Bill To:' FONT '10.Arial'

@ nRow,42, nRow+10,77 DCPRINT BOX GRAY 5
@ nRow+1.5,42, nRow+1.5,77 DCPRINT LINE
@ nRow,43 DCPRINT SAY 'Ship To:' FONT '10.Arial'

nRow += 2
nCol := 5

DCPRINT FONT '12.Courier New'

nSaveRow := nRow

// Print Bill To Name and Address

IF !Empty(aData[INVOICE_BILL_CONTACT])
  @ nRow++, nCol DCPRINT SAY Trim(aData[INVOICE_BILL_CONTACT])
ENDIF
@ nRow++, nCol DCPRINT SAY Trim(aData[INVOICE_BILL_NAME])
@ nRow++, nCol DCPRINT SAY Trim(aData[INVOICE_BILL_ADDR1])
IF !Empty(aData[INVOICE_BILL_ADDR2])
  @ nRow++, nCol DCPRINT SAY Trim(aData[INVOICE_BILL_ADDR2])
ENDIF
@ nRow++, nCol DCPRINT SAY Trim(aData[INVOICE_BILL_CITY]) + ', ' + ;
                           Trim(aData[INVOICE_BILL_STATE]) + ' ' + ;
                           Trim(aData[INVOICE_BILL_ZIP])

nRow := nSaveRow
nCol := 43

// Print Ship To Name and Address

IF !Empty(aData[INVOICE_SHIP_CONTACT])
  @ nRow++, nCol DCPRINT SAY Trim(aData[INVOICE_SHIP_CONTACT])
ENDIF
@ nRow++, nCol DCPRINT SAY Trim(aData[INVOICE_SHIP_NAME])
@ nRow++, nCol DCPRINT SAY Trim(aData[INVOICE_SHIP_ADDR1])
IF !Empty(aData[INVOICE_SHIP_ADDR2])
  @ nRow++, nCol DCPRINT SAY Trim(aData[INVOICE_SHIP_ADDR2])
ENDIF
@ nRow++, nCol DCPRINT SAY Trim(aData[INVOICE_SHIP_CITY]) + ', ' + ;
                           Trim(aData[INVOICE_SHIP_STATE]) + ' ' + ;
                           Trim(aData[INVOICE_SHIP_ZIP])

// Print Heading Box

DCPRINT FONT '10.Arial'

nRow += 5
nCol := 16
@ nRow, 4, nRow+4,77 DCPRINT BOX
@ nRow+1.6, 4, nRow+1.6,77 DCPRINT LINE
@ nRow, nCol, nRow+4,nCol DCPRINT LINE
@ nRow, nCol - 11 DCPRINT SAY 'P.O. No'
nCol += 12
@ nRow, nCol, nRow+4,nCol DCPRINT LINE
@ nRow, nCol - 11 DCPRINT SAY 'S.O. No'
nCol += 12
@ nRow, nCol, nRow+4,nCol DCPRINT LINE
@ nRow, nCol - 11  DCPRINT SAY 'Salesman'
nCol += 12
@ nRow, nCol, nRow+4,nCol DCPRINT LINE
@ nRow, nCol - 11 DCPRINT SAY 'Terms'
nCol += 12
@ nRow, nCol, nRow+4,nCol DCPRINT LINE
@ nRow, nCol - 11 DCPRINT SAY 'Ship Via'
nCol += 12
@ nRow, nCol - 11 DCPRINT SAY 'Ship Date'

nRow += 2
nCol := 16

DCPRINT FONT '8.Arial'

@ nRow, nCol - 11 DCPRINT SAY Trim(aData[INVOICE_PO_NO])
nCol += 12
@ nRow, nCol - 11 DCPRINT SAY Trim(aData[INVOICE_SO_NO])
nCol += 12
@ nRow, nCol - 11 DCPRINT SAY Trim(aData[INVOICE_SALESMAN])
nCol += 12
@ nRow, nCol - 11 DCPRINT SAY Trim(aData[INVOICE_TERMS])
nCol += 12
@ nRow, nCol - 11 DCPRINT SAY Trim(aData[INVOICE_SHIP_VIA])
nCol += 12
@ nRow, nCol - 11 DCPRINT SAY Dtoc(aData[INVOICE_SHIP_DATE])

nRow += 4
nCol := 5
nHeight := 24

// Print Items Box

@ nRow, 4, nRow+nHeight, 77 DCPRINT BOX
@ nRow+2.6, 4, nRow+2.6, 77 DCPRINT LINE

DCPRINT FONT '10.Arial'

@ nRow, nCol DCPRINT SAY 'Part No / '
@ nRow+1, nCol DCPRINT SAY 'Description'
nCol += 29
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + 1  DCPRINT SAY 'Qty'
@ nRow+1, nCol + 1  DCPRINT SAY 'Ord'
nCol += 6
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + 1  DCPRINT SAY 'Qty'
@ nRow+1, nCol + 1  DCPRINT SAY 'Ship'
nCol += 6
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + 1  DCPRINT SAY 'Qty'
@ nRow+1, nCol + 1  DCPRINT SAY 'B/O'
nCol += 6
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + 1  DCPRINT SAY 'U/I'
nCol += 6
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + 1  DCPRINT SAY 'U/Price'
nCol += 8
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + 1  DCPRINT SAY 'Amount'
nCol += 8
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + .4 DCPRINT SAY 'Tax'

nSaveRow := nRow

nRow += 3.6

aItems := aData[INVOICE_ITEMS]

// Print Items

DCPRINT FONT '8.Arial'

FOR i := 1 TO Len(aItems)

  IF Empty(aItems[i,INVOICE_ITEM_DESC])
    EXIT
  ENDIF

  nCol := 5
  nOffset := 0
  IF !Empty(aItems[INVOICE_ITEM_PARTNO])
    @ nRow, nCol DCPRINT SAY Trim(aItems[i,INVOICE_ITEM_PARTNO])
    nOffset++
  ENDIF
  @ nRow+nOffset, nCol DCPRINT SAY Trim(aItems[i,INVOICE_ITEM_DESC])
  nCol += 29

  @ nRow, nCol + 2  DCPRINT SAY aItems[i,INVOICE_ITEM_QTY_ORD] PICT '999' FIXED
  nCol += 6
  @ nRow, nCol + 2  DCPRINT SAY aItems[i,INVOICE_ITEM_QTY_SHIP] PICT '999' FIXED
  nCol += 6
  @ nRow, nCol + 2  DCPRINT SAY aItems[i,INVOICE_ITEM_QTY_BO] PICT '999' FIXED
  nCol += 6
  @ nRow, nCol + 1  DCPRINT SAY Trim(aItems[i,INVOICE_ITEM_UI])
  nCol += 6
  @ nRow, nCol + 1  DCPRINT SAY aItems[i,INVOICE_ITEM_UPRICE] PICT '9999.99' FIXED
  nCol += 8
  @ nRow, nCol      DCPRINT SAY aItems[i,INVOICE_ITEM_AMOUNT] PICT '99999.99' FIXED
  nCol += 8
  IF aItems[i,INVOICE_ITEM_TAXABLE]
    @ nRow, nCol + 1  DCPRINT SAY '*'
  ENDIF

  nRow += 2 + nOffset

NEXT

nRow := nSaveRow + nHeight + 2
nCol := 5
nHeight := 4
nOffset := 2.2

@ nRow, 4, nRow+nHeight,77 DCPRINT BOX
@ nRow+1.8, 4, nRow+1.8,77 DCPRINT LINE

DCPRINT FONT '10.Arial'

@ nRow, nCol DCPRINT SAY 'Non-Taxable'
@ nRow+nOffset,nCol DCPRINT SAY aData[INVOICE_NONTAXABLE] PICT '99999.99'
nCol += 12
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + 1  DCPRINT SAY 'Taxable'
@ nRow+nOffset,nCol DCPRINT SAY aData[INVOICE_TAXABLE] PICT '99999.99'
nCol += 12
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + 1  DCPRINT SAY 'Sales Tax'
@ nRow+nOffset,nCol DCPRINT SAY aData[INVOICE_SALESTAX] PICT '99999.99'
nCol += 12
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + 1  DCPRINT SAY 'Freight'
@ nRow+nOffset,nCol DCPRINT SAY aData[INVOICE_FREIGHT] PICT '99999.99'
nCol += 12
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + 1  DCPRINT SAY 'Misc.'
@ nRow+nOffset,nCol DCPRINT SAY aData[INVOICE_MISC] PICT '99999.99'
nCol += 12
@ nRow, nCol, nRow+nHeight,nCol DCPRINT LINE
@ nRow, nCol + 1  DCPRINT SAY 'Invoice Total' FONT '10.Arial Bold'
@ nRow+nOffset,nCol DCPRINT SAY aData[INVOICE_TOTAL] PICT '99999.99' ;
     FONT '12.Arial Bold'

nRow += 4

// Print comments

DCPRINT FONT '10.Courier New'

cComments := Alltrim(aData[INVOICE_COMMENTS])
nLineCount := MLCount(cComments)
FOR i := 1 TO nLineCount
  cMemoLine := MemoLine( cComments, nil, i )
  @ nRow+i,5 DCPRINT SAY cMemoLine
NEXT

PrintOff(oPrinter)

RETURN nil

* ----------------

PROC appsys
RETURN

* ----------------

Function AS( _cNumber )
RETURN AllTrim( Str( _cNumber ) )

*
Please, can you help me with this?
In my current „hard-writed“ prg code all work like I need, but I don‘t know how do it in your version with locals variables.

TIA
Zdeno

User avatar
rdonnay
Site Admin
Posts: 4733
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: optimize code

#2 Post by rdonnay »

You should be able to add aData and aItems to the LOCAL list. Have you tried that?
The eXpress train is coming - and it has more cars.

Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Re: optimize code

#3 Post by Zdeno Bielik »

hmmm, I not sure, what do you mean, because aData and aItems are declared as Local...

Code: Select all

LOCAL i, GetList[0], aData[INVOICE_ARRAY_SIZE], aItems[10], ...

User avatar
rdonnay
Site Admin
Posts: 4733
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: optimize code

#4 Post by rdonnay »

hmmm, I not sure, what do you mean, because aData and aItems are declared as Local...
Oops. I now see that.

So what variables are you talking about that are not local?
The eXpress train is coming - and it has more cars.

Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Re: optimize code

#5 Post by Zdeno Bielik »

in my current working code in DCGET I have GETID writed directly like GET_DOSPELY or GET_STUDENT and so on......

and in DCHOTKEY variable „o“ is returned from GET_DOSPELY or GET_STUDENT and so on...
and corresponding value(nDospely or nStudent or…) is increased or decreased, but value(nDospely or nStudent) is writed directly now…

Code: Select all

@ nRow, 1 DCSAY 'Dospelý - F1' SAYSIZE 14   SAYID 'SAY_DOSPELY' SAYRIGHT  PARENT oSt_Vst
@ nRow,18 DCGET nDospely  PICTURE '99' GETID 'GET_DOSPELY' GETOBJECT oDospely RANGE 0,99 ;
                VALID { || TestKV( ( nDospely + nStudent + nDochodca + nZajazd + nDieta + nDieta + nVolna ), nVolne ) } ;
                WHEN { || _lNova .and. ! M->plUzavrete .and. M->plSkupExist } ;
                LOSTFOCUS { || DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } ) } PARENT oSt_Vst
@ nRow,24 DCGET bS_L_Dospely WHEN { || .F. } PICT '999.99' GETSIZE 8,1.2 NOTABSTOP GETID obS_L_Dospely PARENT oSt_Vst
@ nRow,33 DCGET bS_CL_Dospely EDITPROTECT { || .T. } PICT '999.99' GETSIZE 8,1.2 NOTABSTOP COLOR GRA_CLR_BLUE, GRA_CLR_BACKGROUND ;
             LOSTFOCUS { || SetAppFocus( oDospely ) } PARENT oSt_Vst



  DCHOTKEY xbeK_F1 ;
          ACTION {|o| IIf( ! M->plUzavrete .and. M->plSkupExist, ;
                           ( o := DC_GetObject(GetList,'GET_DOSPELY'), ;
                             IIf( ( nDospely <= 98 ), nDospely++, NIL ), o:setData(), ;
                             DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } ), ;
                             SetAppFocus( o ) ), ;
                           NIL ) }

So, I want create GETID and bValid “dynamically”, but when I un-remark bValid, in runtime it says that aItems is unknow...
with bValid value I want update column aItems[ i, INVOICE_ITEM_QTY_ORD] with value Quantity and Price

also, with bHotKeyK_P(plus) or bHotKeyK_M(minus) codeblocks I want increase/decrease values like in my original code, but I don’t know, how create codeblocks dynamically...
so in that code must be not directly nDospely, but someting like aItems[i,INVOICE_ITEM_QTY_ORD], I think...

may be somethinh like this:

Code: Select all

                           ( o := DC_GetObject(GetList,'  cGetID '), ;
                             IIf( (aItems[ AS( i ),INVOICE_ITEM_QTY_ORD] <= 98 ), aItems[ AS( i ),INVOICE_ITEM_QTY_ORD]++, NIL ), o:setData(), ;
                             DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } ), ;
                             SetAppFocus( o ) ), ;
sometimes it is e.g. 8 DCGET / DCHOTKEY combinations ( 8 (more or less) same blocks of code where only diference is name of value(-es) ), sometimes more or less...
and I want only one generic block in cycle...
FOR i := 1 TO Len(aItems)
nRow++
@ nRow,2 DCGET aItems[i,INVOICE_ITEM_PARTNO] ;
WHEN {|| .f. } && added
@ nRow,20 DCGET aItems[i,INVOICE_ITEM_DESC] SIZE 30 ;
WHEN {|| .f. } && added

cValid := '{ || aItems[' + AS( i ) + ',INVOICE_ITEM_SUM] := ( aItems[' + AS( i ) + ',INVOICE_ITEM_QTY_ORD] * aItems[' + AS( i ) + ',INVOICE_ITEM_UPRICE] ), dc_qout(aItems) }' && added
bValid := &( cValid ) && added
wtf cValid

cGetID := ( 'GET_F' + AS( i ) ) && added

* hmmm, when I un-remark bValid, in runtime it says that aItems is not declared...

@ nRow,50 DCGET aItems[i,INVOICE_ITEM_QTY_ORD] PICT '9999' ;
; && VALID bValid ; && added
GETID cGetID && added


@ nRow,56 DCGET aItems[i,INVOICE_ITEM_QTY_SHIP] PICT '9999' ;
WHEN {|| .f. } && added
@ nRow,62 DCGET aItems[i,INVOICE_ITEM_QTY_BO] PICT '9999' ;
WHEN {|| .f. } && added
@ nRow,68 DCGET aItems[i,INVOICE_ITEM_UI] GETSIZE 7 ;
WHEN {|| .f. } && added
@ nRow,76 DCGET aItems[i,INVOICE_ITEM_UPRICE] PICT '99999.99' ;
WHEN {|| .f. } && added
@ nRow,88 DCCHECKBOX aItems[i,INVOICE_ITEM_TAXABLE] ;
WHEN {|| .f. } && added
@ nRow,94 DCGET aItems[i,INVOICE_ITEM_SUM] PICT '99999.99' ; && added
WHEN {|| .f. } && added
@ nRow,105 DCGET aItems[i,INVOICE_ITEM_HOTKEY] ; && added
WHEN {|| .f. } && added


nHotKeyK_P := aItems[i,INVOICE_ITEM_HOTKEY_P] && added
nHotKeyK_M := aItems[i,INVOICE_ITEM_HOTKEY_M] && added
wtf nHotKeyK_P, nHotKeyK_M

/*
cHotKeyK_P := ...
( o := DC_GetObject(GetList,' cGetID '), ;
IIf( (aItems[ AS( i ),INVOICE_ITEM_QTY_ORD] <= 98 ), aItems[ AS( i ),INVOICE_ITEM_QTY_ORD]++, NIL ), o:setData(), ;
DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_EXPO_CISLO', 'GET_CAS', 'BROWSER' } ), ;
SetAppFocus( o ) ), ;
*/


cHotKeyK_P := '{ || MsgBox("plus-' + AS( i ) + '") }' && added
* cHotKeyK_P := '{ || MsgBox("plus-' + 'aItems[' + AS( i ) + ',INVOICE_ITEM_SUM]' + '") }' && added
* cHotKeyK_P := '{ |a| a:= aItems[' + AS( i ) + ',INVOICE_ITEM_HOTKEY]' + ', MsgBox("plus-"' + a + ') }' && added
* cHotKeyK_P := '{ |a| a:= aItems[' + AS( i ) + ',INVOICE_ITEM_HOTKEY] }' && added
* cHotKeyK_P := '{ |a| MsgBox( Var2Char( aItems[' + AS( i ) + ',INVOICE_ITEM_HOTKEY] ) ) }' && added
wtf cHotKeyK_P
bHotKeyK_P := &( cHotKeyK_P ) && added
cHotKeyK_M := '{ || MsgBox("minus-' + AS( i ) + '") }' && added
bHotKeyK_M := &( cHotKeyK_M ) && added
wtf cHotKeyK_P, cHotKeyK_M

DCHOTKEY nHotKeyK_P ACTION bHotKeyK_P && added
DCHOTKEY nHotKeyK_M ACTION bHotKeyK_M && added

NEXT

User avatar
rdonnay
Site Admin
Posts: 4733
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: optimize code

#6 Post by rdonnay »

I can't tell you anything based on what you have shown me.

It appears that you don't know how to pass a local variable to another function.
This is a very basic concept.

If you want me to help you, I would need a set of source code that I can compile and run.
The eXpress train is coming - and it has more cars.

Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Re: optimize code

#7 Post by Zdeno Bielik »

ok, attached is little update previosly posted source code,
where I will try demonstrate problems or not correct funcionality

also, when I change aItems from Private to Local, VALID block no more works


ok, please, compile and run program and select TabPage Items


please, put any value into get-item QtyOrd 1 and press Enter
and then press F1 and/or Ctrl+F1 for +/- value in get/item1
codeblocks will be evaluated and associated Gets will be refreshed


1.
well, I can successfully make CodeBlocks for VALID clause, but NOT for LOSTFOCUS or HOTKEYS(see next)
it looks like DC_GetRefresh or DC_GetObject function are ignored or not procesed in CodeBlocks or it is due to fact I can not make correct version for CodeBlock

Code: Select all

  cValid := '{ || M->aItems[' + AS( i ) + ',' + AS( INVOICE_ITEM_SUM ) + ']' ;
         +  ' := ( M->aItems[' + AS( i ) + ',' + AS( INVOICE_ITEM_QTY_ORD ) + '] * M->aItems[' + AS( i ) + ',' + AS( INVOICE_ITEM_UPRICE) + '] ),' ;
         +  ' DC_DebugBrowse( {M->aItems['+AS(i)+']}, {"M->aItems['+AS(i)+']"}, , , ,  , ,  ),' ;
         +  ' DC_GetRefresh(GetList) }'                                                                              && added
  bValid := &( cValid )                                                                                              && added
  wtf cValid


  cGetID   := ( 'GET_F' + AS( i ) )          && added
  cGetID_S := ( 'GET_F' + AS( i ) + 'S' )    && added
  wtf cGetID, cGetID_S


  cLostFocus := '{ || DC_GETREFRESH(GetList) }'   && added
  bLostFocus := &( cLostFocus )                                                                                                           && added
  wtf cLostFocus


  @ nRow,50 DCGET M->aItems[i,INVOICE_ITEM_QTY_ORD] PICT '9999' ;
            VALID bValid ;                                       && added
            GETID cGetID ;                                       && added
            LOSTFOCUS { || DC_GetRefresh(GetList) }              && added
*             LOSTFOCUS bLostFocus                               && added
this doesn’t work even if bLostFocus contains same code like is direct used with LOSTFOCUS in previous example

Code: Select all

  @ nRow,50 DCGET M->aItems[i,INVOICE_ITEM_QTY_ORD] PICT '9999' ;
            VALID bValid ;                                       && added
            GETID cGetID ;                                       && added
             LOSTFOCUS bLostFocus                               && added
with version without LOSTFOCUS clause all objects are not refreshed even if there is in VALID clause command DC_GetRefresh

Code: Select all

  @ nRow,50 DCGET M->aItems[i,INVOICE_ITEM_QTY_ORD] PICT '9999' ;
            VALID bValid ;                                       && added
            GETID cGetID                                        && added

2. here I want instead Do Case/EndCase sequence only one CodeBlock for Plus-HotKeys and one Minus-HotKeys,
but here is problems with DC_GetRefresh and DC_GetObject

Code: Select all

   nHotKeyK_Plus  := M->aItems[i,INVOICE_ITEM_HOTKEY_PLUS]                 && added
   wtf nHotKeyK_Plus


*    cHotKeyK_Plus  := '{|o| ( o := DC_GetObject(GetList, 'GET_F1' ), ;
*                            ; && DC_DebugBrowse( {o:getData()}, {"o:getData()"}, , , ,  , ,  ), ;
*                            IIf( ( M->aItems[ 1, INVOICE_ITEM_QTY_ORD ] <= 98 ), M->aItems[ 1, INVOICE_ITEM_QTY_ORD ]++, NIL ), o:setData(), ;
*                                   M->aItems[ 1, INVOICE_ITEM_SUM ] := ( M->aItems[ 1, INVOICE_ITEM_QTY_ORD ] * M->aItems[ 1, INVOICE_ITEM_UPRICE ] ), ;
*                                   DC_DebugBrowse( {M->aItems[1]}, {"M->aItems[1]"}, , , ,  , ,  ), ;
*                            ; && DC_GETREFRESH( GetList ), ;
*                            DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_TEST1', 'GET_TEST2' } ), ;
*                            SetAppFocus( o ) ) }

   cHotKeyK_Plus  := '{ || MsgBox( "plus - " + Var2Char( M->aItems[' + AS( i ) + ',' + AS( INVOICE_ITEM_SUM ) + '] ) ) }'         && added
   bHotKeyK_Plus  := &( cHotKeyK_Plus )                                                                                                                                                    && added



*    DCHOTKEY nHotKeyK_Plus  ACTION bHotKeyK_Plus                         && added

*    DCHOTKEY nHotKeyK_Minus ACTION bHotKeyK_Minus                        && added


*   added whole case-block
    Do Case
    Case ( i == 1 )
         DCHOTKEY nHotKeyK_Plus ;
            ; && ACTION bHotKeyK_Plus
            ACTION {|o| ( o := DC_GetObject(GetList, 'GET_F1' ), ;
                          ; && DC_DebugBrowse( {o:getData()}, {"o:getData()"}, , , ,  , ,  ), ;
                          IIf( ( M->aItems[ 1, INVOICE_ITEM_QTY_ORD ] <= 98 ), M->aItems[ 1, INVOICE_ITEM_QTY_ORD ]++, NIL ), o:setData(), ;
                                 M->aItems[ 1, INVOICE_ITEM_SUM ] := ( M->aItems[ 1, INVOICE_ITEM_QTY_ORD ] * M->aItems[ 1, INVOICE_ITEM_UPRICE ] ), ;
                                 DC_DebugBrowse( {M->aItems[1]}, {"M->aItems[1]"}, , , ,  , ,  ), ;
                          ; && DC_GETREFRESH( GetList ), ;
                          DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_TEST1', 'GET_TEST2' } ), ;
                          SetAppFocus( o ) ) }
         DCHOTKEY nHotKeyK_Minus ;
            ACTION {|o| ( o := DC_GetObject(GetList, 'GET_F1' ), ;
                          ; && DC_DebugBrowse( {o:getData()}, {"o:getData()"}, , , ,  , ,  ), ;
                          IIf( ( M->aItems[ 1, INVOICE_ITEM_QTY_ORD ] >= 1 ), M->aItems[ 1, INVOICE_ITEM_QTY_ORD ]--, NIL ), o:setData(), ;
                                 M->aItems[ 1, INVOICE_ITEM_SUM ] := ( M->aItems[ 1, INVOICE_ITEM_QTY_ORD ] * M->aItems[ 1, INVOICE_ITEM_UPRICE ] ), ;
                                 DC_DebugBrowse( {M->aItems[1]}, {"M->aItems[1]"}, , , ,  , ,  ), ;
                          ; && DC_GETREFRESH( GetList ), ;
                          DC_GETREFRESH( GetList, nil, DCGETREFRESH_ID_EXCLUDE, { 'GET_TEST1', 'GET_TEST2' } ), ;
                          SetAppFocus( o ) ) }

    Case ( i == 2 )
*        ...

*        3-9 ...

    Case ( i == 10 )
*        ...
    EndCase

if you remove whole DoCase/EndCase part and add this next part, this simple version works,
so, I have problem with currently complex condition used in previous ACTION clause, there is DC_GetRefresh and DC_GetObject

Code: Select all

   nHotKeyK_Plus  := M->aItems[i,INVOICE_ITEM_HOTKEY_PLUS]                 && added
   cHotKeyK_Plus  := '{ || MsgBox( "plus - " + Var2Char( M->aItems[' + AS( i ) + ',' + AS( INVOICE_ITEM_SUM ) + '] ) ) }'         && added
   bHotKeyK_Plus  := &( cHotKeyK_Plus )                                 && added

   DCHOTKEY nHotKeyK_Plus  ACTION bHotKeyK_Plus                         && added


3.
mark/delete Private aItems and unmark/add Local aItems

and now, when you unremark bValid, in runtime it says that aItems is unknow
in tested code aItems is declared like Private, so, if it is possible, I want same functionality when i tis declared like Local



I hope, it is better to understand now, what I asked you – many thanks

TIA
Zdeno
Attachments
invoice.zip
(7.04 KiB) Downloaded 675 times

Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Re: optimize code

#8 Post by Zdeno Bielik »

Roger

please, did you have a little time to look on it?

TIA
Zdeno

User avatar
rdonnay
Site Admin
Posts: 4733
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: optimize code

#9 Post by rdonnay »

please, did you have a little time to look on it?
I will look at it tomorrow.
The eXpress train is coming - and it has more cars.

User avatar
rdonnay
Site Admin
Posts: 4733
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: optimize code

#10 Post by rdonnay »

Your problem is a misunderstanding of how to use code blocks.

For some reason, you are macro-compiling a code block when there is no reason to do this unless you are creating some kind of data-driven system.

This:

Code: Select all

  cValid := '{ || M->aItems[' + AS( i ) + ',' + AS( INVOICE_ITEM_SUM ) + ']' ;
         +  ' := ( M->aItems[' + AS( i ) + ',' + AS( INVOICE_ITEM_QTY_ORD ) + '] * M->aItems[' + AS( i ) + ',' + AS( INVOICE_ITEM_UPRICE) + '] ),' ;
         +  ' DC_GetRefresh(GetList) }'                                                                            
  bValid := &( cValid )   


Should be this:

Code: Select all

  bValid := { || aItems[i,INVOICE_ITEM_SUM] := (aItems[i,INVOICE_ITEM_QTY_ORD] * aItems[i,INVOICE_ITEM_UPRICE] ), ;
          DC_GetRefresh(GetList) }   


Why do you think you need a macro?
The eXpress train is coming - and it has more cars.

Post Reply