Process statistics in database guidence

Process statistics in database guidence

Postby Marc Venken » Fri Dec 21, 2018 4:21 pm

Hello,

For my personel invoice program, i want to change the logic for processing invoice values.

In early days, I hard coded into the dbf (Will stay with DBF) fields like :

Tot_2017, Tot_2016, Tot_2015, ... Tot_1994
Per_2017, Per_2016, ....
etc..

And in source I had stuff like

replace Tot_2017 with .....
replace Tot_2016 with......

So this year again, I will have to change my source and add structure of the database to fit 2019, 2020

I know this is bad practice...

How do you process detailed data for 1-5 year for statistics on screen (totals) with probably the same fields in the database ?

The most logic will be :

Year1, Year2, ...Year5 and than change headers of Xbrowse according 2019,2018...

At start of a new year I need to process again only the detail from 5 years including 2019 as start.

I hope I make any sense.

I gone update this into my 32 bit version i'm working on.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1357
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Process statistics in database guidence

Postby ukoenig » Fri Dec 21, 2018 8:48 pm

Marc,

my solution to check business done.
It might be a little bit more what You need.
Check products of any year against each other with month splitting.
Using many products the browser header will be jan - Dec
and the list are the products.

Image

regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Process statistics in database guidence

Postby reinaldocrespo » Mon Dec 24, 2018 4:46 pm

Hello Marc;

If I understand your comments/question; my suggestion would be to add records instead of columns for each year. The structure of the .dbf would look similar this:

Year N 4 0
TotalSales N 9 2
TotalPer N 9 2
...

Adding a new year would simply add another record to the dbf. No need to change table structure.

Hope that helps,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Process statistics in database guidence

Postby James Bott » Fri Dec 28, 2018 11:15 pm

Marc,

You could also get these numbers with an invoice database class. You just subclass from TDatabase and add a method for TotalSales( cYear ). So you would just do this:

Code: Select all  Expand view
oInvoices():= TInvoices():New()
oInvoices:TotalSales( year(date()) ) // returns Year-to-date sales for current year
oInvoices:TotalSales( year(date())-1 ) // returns last year's sales
oInvoices:TotalSales( 2015 ) // returns sales for the year 2015
 

You can do whatever you want with the results, display via MsgInfo(), put in a database (as Reinaldo suggests), or directly into a report or a browse of a temp file. Granted re-reading all the files from past years whenever you generate a report is not the most efficient, but the nice thing is that you always use the same call to get what you need. So, oInvoices:TotalSales( nYear ) could work something like this.

Code: Select all  Expand view
Method TotalSales( nYear ) Class TInvoices
   Default nYear:= year(date())
If nYear = Year(date())
   // read all invoices this year and sum
else
   // read sales total from total sales database file (2 fields, year and TotalSales)
endif
Return nTotalSales

 

This way, you can change the method of finding the data at any later date and any code that is using oInvioces:TotalSales() will not break.

Food for thought.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Process statistics in database guidence

Postby Marc Venken » Sat Dec 29, 2018 10:50 am

James,

I surely go for classes !

You have convinced me a while ago with several samples ...

And also for this, classes seems to be the right way.

BTW. The forum samples you posted about classes. (not only mine). By any chance that you have them in a sepperate folder on your system ?
It could be very usefull for samples as a starting point.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1357
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests