Eddie Monster
8th August 2003, 18:52
I am trying to create a session that allows our HR department to track Vacation hours by Salaried Employee. I have created a table (tiosd000) that stores:
tiosd000.emno - employee number (indexed)
tiosd000.year - year vacation is taken (indexed)
tiosd000.date - date vacation is taken (indexed)
tiosd000.evac - employee vacation taken
tiosd000.epto - employee paid time off taken
tiosd000.flag - flag to prevent modifcation of record after initial entry

Here is my code to date:

|******************************************************************************
| Written by: Eric Edder
| Request: TR 964
|
| This session processes employee Vacation and Paid Time Off (PTO) balances.
| There are two different session, one for hourly employees and the other for
| salary employees (this session). Hourly employees vacation/PTO balances are
| updated based on hours accounting records coded with the indirect tasks for
| Personal Time and Vacation. Salaried employees are updated separately by HR
| data entry.
|
|****************************** DECLARATION SECTION ***************************
declaration:

table ttccom001 | Employee Master
table ttiosd000 | Salaried Employee Vacation/PTO

| Selection Criteria

| Working Storage

|****************************** PROGRAM SECTION ***************************
|****************************** ZOOM FROM SECTION ***************************
|****************************** FORM SECTION ***************************

form.1:
init.form:
get.screen.defaults()

|****************************** CHOICE SECTION ***************************

choice.update.db:
before.choice:
tiosd000.flag = 1 | Sets flag from 0 to 1. In the Form Field
| section it is set not to allow input into
| the field if this flag is 1. This prevents
| the user from changing the data and not having
| the Vacation/PTO balances modified to follow.

|****************************** FIELD SECTION ***************************

field.tiosd000.emno:
after.input:
get.emno.data()

field.tiosd000.epto:
after.input:
execute(update.db)


|****************************** MAIN TABLE SECTION ***************************
main.table.io:
after.read:
get.emno.data()

after.write:
recalculate.vacation.pto()

|****************************** FUNCTION SECTION ***************************
functions:

|******************************************************************************
| This function pulls the employee name, vacation balance and PTO balance from
| the employee master and displays them on the form.
|******************************************************************************
function get.emno.data()
{
select tccom001.nama, tccom001.evac, tccom001.epto
from tccom001
where tccom001.emno = :tiosd000.emno
selectdo
display("tccom001.nama")
display("tccom001.evac")
display("tccom001.epto")
endselect
}

|******************************************************************************
| This function deducts the Vacation/PTO from the balance in the employee
| master and then updates the employee master with the new value.
|******************************************************************************
function recalculate.vacation.pto()
{
select tccom001.evac, tccom001.epto
from tccom001
for update
where tccom001.emno = :tiosd000.emno
selectdo
tccom001.evac = tccom001.evac - tiosd000.evac
tccom001.epto = tccom001.epto - tiosd000.epto
db.update(ttccom001,db.retry)
commit.transaction()
endselect
}

|****************************** END OF SCRIPT ***************************


I am using a type 3 form so that users can see the total vacation balance left as well as the detail transactions showing when vacation was taken. The problem I have is this. The users want the vacation balance to be updated as they enter records. If you enter a line of data the first time after the form opens, the employee master (tccom001) is updated with the vacation taken after you tab past the last multi-occ field for that record. After that it doesn't update at all no matter how many records you put in. I've looked in the Library for Form commands to see if there is something there. Either there isn't or I don't understand some of those commands and thier functionality (very possible). Any suggestions or help would be greatly appreciated.

Thanks in advance!

mark_h
8th August 2003, 20:33
I am assuming you have a form that looks like this:

Employee Name: xxxxx <--tccom001.nama
Employee Number: xxxx <--tccom001.emno
Vacation Balance: xxx <--balance

date leave taken
xx-xx-xx xxx

Balance is the form field and it and leave taken are in hours. Also date and leave taken are the appropriate tiosd000 table fields. Now as your user enters dates and leave taken they want the balance to be updated. Note that what the user sees and actually updating tccom001 are different.

field.balance:
after.input:
balance = balance - tiosd000.evac
display("balance")

then in

after.update.db.commit:
update_balance_tccom001()

In reality the tccom001 table does not get updated until the user pushes the save button. The update_balance_routine would then go get the new records that you just added. Maybe even add a process flag onto the table so you know which ones have been processed into the original tccom001 balance.

I do something like this with input totals on one of my sessions. To get the initial balance you can use the choice.first.set or maybe the main.table.io/after.read section. I know I use it in both the choice.first.set section and even in the choice.end.program, because no telling what the users may do to abruptly end the program. Just thought this might work for you also.

Mark

Eddie Monster
8th August 2003, 21:26
Got the idea. I'll have to make a few modifications, but it looks great. Thanks!