Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Running Totals in a Grid
Message
 
À
17/03/2002 11:10:29
Rick Hawkins
Rose Valley Software Studio
Wallingford, Pennsylvanie, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00633884
Message ID:
00633896
Vues:
11
Hi,

You might consider the method I use. I have three text boxes placed horizonally just below
the grid. The first displays the sum of the invoice assigned to a particular
Cost/Revenue Center. The second displays the sum of the total invoice. The third displays the sum of the total account. Each text box is updated as
the user moves up and down within the grid. The afterrowcolumn event of the
grid is used to call a custom method called sum_amounts. Key expressions for the three text boxes are built from the the current row. I have an index
on a field named cleared that hold a N for no if the row is part of an invoice that sum to a non-zero balance. Most of the transactions contain Y for yes in the cleared field, so even if their is thousands of row for a particular parent, only a few records would normally be in the the_add index as uncleared, because that whole
purpose of the system is to bring an invoice back to a cleared or zero state by collecting the outstanding amount or a write-off entry. I have found the calculation of the three text boxes to be instantanious even when holding the
ALT+NEXT key down and moving quickly through the parent table. The next button also calls the sum_amounts method. Below is the code in the sum_amount method:

****************************************************

Parameters arcur_filter
thisform.LockScreen = .T.
Set Delete On
Select arcur
If Recno([arcur])<>0
Thisform.pageframe1.Page2.div_amt_label.Caption="CRC# "+Str(arcur.divno,6,0)+" Inv: "+Str(arcur.INVOICE,7,0)
Thisform.pageframe1.Page2.inv_amt_label.Caption="Inv: "+Str(arcur.INVOICE,7,0)
Else
Thisform.pageframe1.Page2.inv_amt_label.Caption=""
Thisform.pageframe1.Page2.div_amt_label.Caption=""
Endif
If Eof()
Thisform.pageframe1.Page3.previous_amt.Value=0
Thisform.pageframe1.Page3.current_amt.Value=0
Thisform.pageframe1.Page3.sum_amt.Value=0
Thisform.pageframe1.Page2.amt_tot.Value=0
Thisform.pageframe1.Page2.inv_amt.Value=0
Thisform.pageframe1.Page2.div_amt.Value=0
&& Remember no child rows for this parent
Endif
*-- Select the alias specified in the grid's RecordSource property
Select (Thisform.pageframe1.Page2.grid_lines.RecordSource)
lnOldRecNo = Iif(Eof(), 0, Recno())
temp_previous=0
temp_current=0
temp_inv_amt=0
temp_div_amt=0
Select arcur
If Empty(Thisform.find_filter)=.T.
Set Order To Tag the_add
Endif
&&Remember get keys from the current pointer
div_the_expr=[STR(arcur.cno,8,0)+STR(YEAR(arcur.invdate),4)+STR(MONTH(arcur.invdate),2)+ ;
STR(DAY(arcur.invdate),2)+STR(arcur.invoice,7,0)="]+ ;
STR(arcur.cno,8,0)+Str(Year(arcur.invdate),4)+Str(Month(arcur.invdate),2)+ ;
STR(Day(arcur.invdate),2)+Str(arcur.INVOICE,7,0)+Str(arcur.divno,6,0)+["]

inv_the_expr=[STR(arcur.cno,8,0)+STR(YEAR(arcur.invdate),4)+STR(MONTH(arcur.invdate),2)+ ;
STR(DAY(arcur.invdate),2)+STR(arcur.invoice,7,0)="]+ ;
STR(arcur.cno,8,0)+Str(Year(arcur.invdate),4)+Str(Month(arcur.invdate),2)+ ;
STR(Day(arcur.invdate),2)+Str(arcur.INVOICE,7,0)+["]

Seek Str(Thisform.clientno1.Value,8,0) && remember position on first row
If Found()
Wait Window [Calculating . . .] Nowait
For i = 1 To 100000000
If arcur.cno <> Thisform.clientno1.Value
Exit
Else
If .Not. Deleted() .And. .Not. .F. .And. .Not. arcur.cleared="Y"
Do Case
Case Recno([arcur])>0
temp_previous=temp_previous+arcur.amount
Case Recno([arcur])<0
temp_current=temp_current+arcur.amount
Otherwise
&& not currently used
Endcase
&& Remember current Invoice
div_curr_expr=[STR(arcur.cno,8,0)+STR(YEAR(arcur.invdate),4)+STR(MONTH(arcur.invdate),2)+ ;
STR(DAY(arcur.invdate),2)+STR(arcur.invoice,7,0)="]+ ;
STR(arcur.cno,8,0)+Str(Year(arcur.invdate),4)+Str(Month(arcur.invdate),2)+ ;
STR(Day(arcur.invdate),2)+Str(arcur.INVOICE,7,0)+Str(arcur.divno,6,0)+["]

inv_curr_expr=[STR(arcur.cno,8,0)+STR(YEAR(arcur.invdate),4)+STR(MONTH(arcur.invdate),2)+ ;
STR(DAY(arcur.invdate),2)+STR(arcur.invoice,7,0)="]+ ;
STR(arcur.cno,8,0)+Str(Year(arcur.invdate),4)+Str(Month(arcur.invdate),2)+ ;
STR(Day(arcur.invdate),2)+Str(arcur.INVOICE,7,0)+["]

If div_curr_expr=div_the_expr
temp_div_amt=temp_div_amt+arcur.amount
Endif
If inv_curr_expr=inv_the_expr
temp_inv_amt=temp_inv_amt+arcur.amount
Endif
Endif
Skip
Endif
Endfor
Wait Clear
Thisform.pageframe1.Page3.previous_amt.Value=(temp_previous)
Thisform.pageframe1.Page3.current_amt.Value=(temp_current)
Thisform.pageframe1.Page3.sum_amt.Value=(temp_previous+temp_current)
Thisform.pageframe1.Page2.amt_tot.Value=(temp_previous+temp_current)
Thisform.pageframe1.Page2.inv_amt.Value=(temp_inv_amt)
Thisform.pageframe1.Page2.div_amt.Value=(temp_div_amt)
Else
Thisform.pageframe1.Page3.previous_amt.Value=0
Thisform.pageframe1.Page3.current_amt.Value=0
Thisform.pageframe1.Page3.sum_amt.Value=0
Thisform.pageframe1.Page2.amt_tot.Value=0
Thisform.pageframe1.Page2.inv_amt.Value=0
Thisform.pageframe1.Page2.div_amt.Value=0
Endif
If .Not. Empty(clint.credit_lt)
If Thisform.pageframe1.Page2.amt_tot.Value > clint.credit_lt
cMessageTitle = 'Credit Limit Exceeded'
cMessageText = 'Warning . . . Credit limit is '+Str(clint.credit_lt,9,2)+' and current balance is '+;
STR(Thisform.pageframe1.Page2.amt_tot.Value,11,2)
nDialogType = 0 + 16
* 0 = OK
* 16 = Stop Sign Icon
nAnswer = Messagebox(cMessageText, nDialogType, cMessageTitle)
Endif
Endif
If Empty(Thisform.find_filter)=.T.
Set Order To Tag Main
Endif
Select arcur
If lnOldRecNo <> 0
Go lnOldRecNo
Endif
Thisform.pageframe1.Page3.previous_amt.Refresh
Thisform.pageframe1.Page3.current_amt.Refresh
Thisform.pageframe1.Page3.sum_amt.Refresh
Thisform.pageframe1.Page2.amt_tot.Refresh
Thisform.pageframe1.Page2.inv_amt.Refresh
Thisform.pageframe1.Page2.div_amt.Refresh
Set Delete Off
thisform.LockScreen = .F.
Return

************************************************************
The sum_amounts method is called in many other places in my
forms like when a record is deleted or anywhere the amount
of the parent's account may have changed.
Leland F. Jackson, CPA
Software - Master (TM)
smvfp@mail.smvfp.com
Software Master TM
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform