mav910623 Posted April 7, 2009 Share Posted April 7, 2009 Hi guys. I have this Car Rental Script and would like to change so price issues. The thing is the system chargers extra hours of rental by calculating the daily price divided against 24. This creates uneven numbers when proceeding to checkout phase. I would like to change the script to give a fixed price of 20 but it is not working. Mind you look at the .php file and help me out . Here iss a snippet of the code. // looks up each day, works out the price and calclates the total, slow because if 7 days are chosen then this loop and query runs 7 times, but the only way to do this so that each day rate is calculated. for ($counter = $starttime[0]+1; $counter <= $numberofHours; $counter += 1) { $value = date("Y-m-d", mktime($startdateArray["hours"] + $counter,$startdateArray["minutes"],$startdateArray["seconds"],$startdateArray["mon"],$startdateArray["mday"],$startdateArray["year"])); $sql="SELECT * FROM #__carman_prices WHERE uid='".$uid."' AND ('".$value."' BETWEEN startdate AND enddate)"; $database->setQuery($sql); $rows = $database->loadObjectList(); $hourlyprice=$rows[0]->dayprice/24; $total = $total + $hourlyprice; } } else { // this puts each day in the date range into and array... $date_array = carman_Calendar::date_range($sdateArray[0],$fdateArray[0]); foreach ($date_array as $value) { $sql="SELECT * FROM #__carman_prices WHERE uid='".$uid."' AND ('".$value."' BETWEEN startdate AND enddate)"; $database->setQuery($sql); $rows = $database->loadObjectList(); $weekprice=$rows[0]->price; //$dailyprice=$rows[0]->dayprice; $weeklydayprice=$weekprice/7; //$dailytotal = $dailytotal+$dailyprice; $total = $total+$weeklydayprice; } } Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 7, 2009 Share Posted April 7, 2009 Try floor() with your division and % (modular division) - not sure this is what you want but I'm not sure I entirely understand your question. $hourlyprice=floor($rows[0]->dayprice/24); $hourlyprice2=$rows[0]->dayprice%24; Using / will give you floating (aka decimal) results using floor() will round it down to the nearest integer. The modular part (%) will give you the remainder. You can always ECHO the values out to see if they're what you should be using. Quote Link to comment Share on other sites More sharing options...
mav910623 Posted April 7, 2009 Author Share Posted April 7, 2009 Thanks For the quick reply urm, what i would actually like to do is set the code to charge an additional $20 for every hour rather than just calculate the actual cost or renting the said car for an extra hour u get what i mean? Example: Car A cost $24 a day, with the current script it would charge an extra $1 for each extra hour. like the script says dayprice/24 What i want is for the script to charge $20 as a flat rate no matter how much the rental of said car is per day.. Hope you guys get it this time... if u need the entire script just let me know maybe something else is affecting it.. cheers Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 7, 2009 Share Posted April 7, 2009 I'll do my best to answer but someone here is playing very fast trance very loud in the office and I can't hear myself think! Have you got the number of hours the car has been rented out? Can't you just multiply that by 20 and add that to the amount? Quote Link to comment Share on other sites More sharing options...
mav910623 Posted April 8, 2009 Author Share Posted April 8, 2009 Hey I Tried what you said but my additional code makes the script completely dysfunctional. . . can you take a look at it? :-\ [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 8, 2009 Share Posted April 8, 2009 What's the ELSE for? I can't see an if() statement - which piece of code is it that isn't behaving, before or after the ELSE? Or do we need to see the entire if() structure? Quote Link to comment Share on other sites More sharing options...
mav910623 Posted April 8, 2009 Author Share Posted April 8, 2009 I really am unsure about the code structure as i was not the one who wrote it.. Im just editting. All i vae done is added $flatrate = $numberofHours * 20; $total = $total + $flatrate; and it stopped working as soon as i revert it back to original it worked.. there was no other modification done... Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 9, 2009 Share Posted April 9, 2009 So do we have various cars with different rates depending on what they are and you want all cars to be charged at a flat rate of $20 per day? If I still don't have it - a look at all the source would probably be handy in this case. Quote Link to comment Share on other sites More sharing options...
mav910623 Posted April 9, 2009 Author Share Posted April 9, 2009 So do we have various cars with different rates depending on what they are and you want all cars to be charged at a flat rate of $20 per day? If I still don't have it - a look at all the source would probably be handy in this case. Yup that almost rite.. i would like to charge a flat rate of $20 per additional hour the car is booked. i just don't have the source that's the problem... you mid going over the php file for me ? h Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.