Gossamer Forum
Home : Products : DBMan : Customization :

auto add a value to an entry

Quote Reply
auto add a value to an entry
Hi all,

My problem: we have recently changed an odometer on one of our fire engines. Naturally, the new odometer reads 0; but the rest of the engine has about 36,000 miles worth of wear on it.

I would like to automatically add the value of the original odometer to whatever mileage number is entered in a new record entry. Thus, if a new record is entered with a mileage of 117, it would be stored as "117 + 36000". or 36,117.

I am using the record entry preview mod, and thought that this would be the appropriate place to make the change.

I'd appreciate any thoughts or suggestions! Thank you...

-rckeller
"I can think of no more stirring symbol of Man's humanity to Man than a Fire Engine."
Quote Reply
Re: [rckeller] auto add a value to an entry In reply to
You mean each time a new record is added to the database you want to have it add 36,000 to that field?

If you have a current record and modify it, why not just make the adjustments when you modify the record.

I'm just wondering why every record would end up having the same number of miles automatically added to with a new record.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [rckeller] auto add a value to an entry In reply to
since you don't want it to apply to all records, just records for one truck, you could add a new field to the database, say old_odometer and set the initial value to zero. enter the 36000 in that field for just that one truck. then when you display odometer readings add that field to the individual entry to get the total. the other trucks would have 0 in that field. then you would have the flexibility to add a new odometer to any truck, even multiple times, and set each truck's previous total individually.
tip: i always set up a field called reserved that is hidden and has a default/required value of xxxxx. that way i can easily add a new field before or after it by downloading the file and opening in wordpad or something and doing search and replace to change |xxxxx| to ||xxxxx|
Quote Reply
Re: [delicia] auto add a value to an entry In reply to
Ah... thank you, I will try this!

-rckeller
"I can think of no more stirring symbol of Man's humanity to Man than a Fire Engine."
Quote Reply
Re: [LoisC] auto add a value to an entry In reply to
Sorry, perhaps I was unclear. Our FD has 26 vehicles; but only 1 has had its odometer replaced. The new odometer in that vehicle reads 0 - though the vehicle itself has about 36,000 miles of wear on it. Whenever someone adds a new workorder for that vehicle in the DBMan database, I need to add the miles from the original odometer to whatever value the new odometer reads. But this applies only to 1 vehicle; for all the others, the mileage as recorded on the odometer is in fact the correct mileage.

Thanks!
-rckeller
"I can think of no more stirring symbol of Man's humanity to Man than a Fire Engine."
Quote Reply
Re: [rckeller] auto add a value to an entry In reply to
are you using relational database mod? how are you identifying which vehicle the work order relates to?
Quote Reply
Re: [delicia] auto add a value to an entry In reply to
Hi,

I was going to try an if-then-else statement in the html.

The engine # is identified before the mileage. I don't have the correct syntax for it yet, but functionally it would act as follows:

IF $EngineNo = 901
THEN $mileage = standard input value + 36000
ELSE $mileage = standard input value

And, as I do use the Preview Record mod, I figured that this would be the point at which the server would be able to sum the input and the fixed value for the relevant engine, or just use the input value for all the others.

Does that make sense?
"I can think of no more stirring symbol of Man's humanity to Man than a Fire Engine."
Quote Reply
Re: [rckeller] auto add a value to an entry In reply to
i guess my tendency would be to overcomplicate things and have a relational database. one would be the truck database that had truck#, base mileage and any other info related to the truck. then i would have a separate database of workorders that related to the truck with a truck# field and it would have info about the work order. then for reporting purposes i would pull the truck info from the truck database (including the base mileage, which in your case would be zero for 25 trucks and 36000 for one truck). then the base mileage would be added to the mileage on the workorders. too complicated, huh?

i've never used or looked at the preview mod, but that does sound like the right place. does it force you to preview or do you have the option to enter without previewing? if it's optional, i think you'll need to put the code in a different place.
Quote Reply
Re: [rckeller] auto add a value to an entry In reply to
Do you have a notes field in your database? I still think it would be easier to either manually add the 36000 miles to the field by modifying the record, or have a field to make a notes of when the part was replaced including date, etc.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [rckeller] auto add a value to an entry In reply to
Here's another method:

1, Under html_record_form near the top of the page add the following:
---------------------------------------------------------------------

|;
if ($in{'modify'}) {
print qq|
<SCRIPT LANGUAGE="JavaScript">
function calcMiles() {
form.real_miles.value = (form.mileage.value + 36000);
</SCRIPT>|;
}
print qq|

<INPUT TYPE="hidden" NAME="real_miles" VALUE="$rec{'real_miles'}">


2. Add this to your mileage/odometer reading tag:
-------------------------------------------------

|; if($in{'modify'}) {print qq|onChange="calcMiles()"|;} print qq|


EXAMPLE: <INPUT TYPE="text" NAME="mileage" VALUE="$rec{'mileage'}" |; if ($in{'modify'}) {print qq|onChange="calcMiles()"|;} print qq|>


3. Add this field to your default.cfg file:
(don't forget to add the new field to each existing record in default.db)
-------------------------------------------

real_miles


4. Then under html_record add this statement for yourself:
----------------------------------------------------------

|;
if ($per_admin) {
print qq|
Real Mileage: $rec{'real_mileage'}
|;
}
print qq|


I haven't tested this so use it as a guide (save a backup copy of your html.pl if you want to use it.)