Gossamer Forum
Home : Products : DBMan : Installation :

JPDeni, Alex, I got one for you

Quote Reply
JPDeni, Alex, I got one for you
Hi,

Alex, JPDeni, You are the DBman wizards, and so I have a tough one for you.

I have a field named List Price, here I enter the retail price for an item. Under that I have a field named Our Price, here I enter the price which we charge for that item (25% off). So what I had to do is, manually calculate 25% off each item using a calculator (What Stress Frown. So here is the question. Is it possible that when I enter a price in the List Price field, it automatically takes off 25%, and I don't even have to see the Our Price field, it enters it in to the database by itself.

I know this sounds a little complicated. Actually to me it sounds a lot complicated. But Alex or JPDeni or whoever can help me, you will be saving me days of work.

I very much appreciate it.

------------------
Thanks
JFrost

Quote Reply
Re: JPDeni, Alex, I got one for you In reply to
Do you really need to have it the discounted price entered into the database, or would it be okay to just have the discounted price displayed? It's easier to change the value that is displayed than it is to change the value before it's put into the database. Also, if you ever change the amount that your company discounts prices, you'd just need to change one thing in html_record, rather than changing every price in your database.

You would put the following code in html_record, just after
my (%rec) = @_;

If you have a dollar sign in your field, you'll need to get rid of that--

Code:
$rec{'List Price'} = substr($rec{'List Price'},1,length($rec{'List Price'})-1);

If don't have a dollar sign, just forget the above line.

The real nitty-gritty is the next line
Code:
$OurPrice = sprintf("%.2f",$rec{'List Price'} * .75);

This discounts the price by 25% and rounds it. (This time I ran it through Perl on my own computer and pasted the code. Shouldn't be any typos here! Smile )

Just for completeness, in case you started by putting dollar signs in and then changed it later on but don't want to go back and change all your previous entries:

Code:
if (substr($rec{'List Price'},0,1) eq '$') {
$rec{'List Price'} = substr($rec{'List Price'},1,length($rec{'List Price'})-1);
}
$OurPrice = sprintf("%.2f",$rec{'List Price'} * .75);

If you want to put the dollar sign back in when you print it out, use

\$$OurPrice
\$$rec{'List Price'}

I think I've covered all the bases. Let me know if there's something else I didn't think of. Smile

------------------
JPD

PS I thought of one other thing. Smile

If you're using autogenerate for your record display, change all instances of $OurPrice to $rec{'Our Price'} or whatever your field name is for the discounted price.

If you want to put the dollar signs in with autogenerate, use
$rec{'List Price'} = '$'.$rec{'List Price'};
$rec{'Our Price'} = '$'.$rec{'Our Price'};

[This message has been edited by JPDeni (edited February 17, 1999).]