
kit123321
Members-
Posts
16 -
Joined
-
Last visited
Profile Information
-
Location
Hong Kong
kit123321's Achievements

Member (2/5)
0
Reputation
-
when i click button .btnStart, i would like to INPUT class="stime" to have value $resp['start'] without page reload. but not work. any help? JS code $(".btnStart").click( function() { var tid = $(this).data("tid") $.get( "", {"ajax":"startBooking", "tid":tid}, function(resp) { $(".sdate[data-tid="+tid+"]").val(resp.sdate).show() $(".stime[data-tid="+tid+"]").val(resp.start).show() $(".bid[data-tid="+tid+"]").val(resp.bid) }, "JSON" ) $(this).hide() $(".btnFinish[data-tid="+tid+"]").show() }) PHP Handle AJAX ## Handle AJAX requests if ($_GET['ajax'] == 'startBooking') { $dt = new DateTime('now'); $start = $dt->format('Y-m-d H:i:s'); $st = $dt->format('H:i'); $sd = $dt->format('Y-m-d'); $stmt = $pdo->prepare("INSERT INTO table_booking (table_id, start_time) VALUES (?, ?)"); $stmt->execute( [ $_GET['tid'], $start ] ); $bid = $pdo->lastInsertId(); $resp = [ "bid" => $bid, "start" => $st, "sdate" => $sd ]; exit( json_encode($resp)); } HTML <input type='time' class='stime' value='$st' data-tid='{$r['tid']}'>
-
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
Thank you so much for your help, i am still learning your script. your help is very useful. -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
i found that missing Holiday which is same calculation with Weekend cost. 2022-05-02 2022-05-09 2022-09-12 i am thinking what is the best way to add with this Holiday array. -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
Thanks Barand for the reply. Let's me understand and study your script. give me a sec. -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
Yeah, Barand. you are correct. sorry my mistake that i am talking row, not column. but i find that, when the period more than one day, the calc not correct. Pic1 - correct if only 1 day. Pic2 - incorrect if more than 1 day. -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
i am sorry about that, since i would like you to check the output. <?php class PriceCalculator { private $start; private $end; private $price = [ 0 => [ 98, 128], 1 => [ 88, 118], 2 => [ 88, 118], 3 => [ 88, 118], 4 => [ 88, 118], 5 => [ 88, 118], 6 => [ 98, 128] ]; public function __construct ($time1, $time2) { $this->start = new DateTime($time1); $this->end = new DateTime($time2); } public function calculate() { $total = 0; $dp = new DatePeriod($this->start, new DateInterval('PT1M'), $this->end ); foreach ($dp as $min) { $day = $min->format('w'); $peak = '02' <= $min->format('H') && $min->format('H') < '18' ? 0 : 1; $total += $this->price[$day][$peak]/60; } return number_format($total, 2); } } $time1 = "2022-04-11 16:05:00"; $time2 = "2022-04-11 18:12:00"; $instance = new PriceCalculator($time1, $time2); echo $instance->calculate(); // 242.53 $rentals = [ [ "2022-04-11 16:05:00", "2022-04-11 18:00:00" ], [ "2022-04-11 18:00:00", "2022-04-11 18:12:00" ] ]; echo '<pre>'; foreach ($rentals as $times) { $instance = new PriceCalculator($times[0], $times[1]); printf('%s | %s | %10s<br>', $times[0], $times[1], $instance->calculate()); } echo '</pre>'; -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
like this right hand size output is what i want. $time1(Start time) & $time2(End time) are variables, so the $rentals array should be automatically value from $time1,2. -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
i still have no idea how to breakdown the date range into column automatically. any hint? -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
do you have any idea? -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
Yes, you correct that my example calculations mistake, thanks for correction. and Yes, that's what i need for the cost breakdown, but $time1 and $time2 are variable. for example. $time1 = "2022-04-11 16:05:00"; $time2 = "2022-04-11 18:12:00"; $rentals = [ [ "2022-04-11 16:05:00", "2022-04-11 18:00:00" ], [ "2022-04-11 18:00:00", "2022-04-11 18:12:00" ] ]; echo '<pre>'; foreach ($rentals as $times) { $instance = new PriceCalculator($times[0], $times[1]); printf('%s | %s | %10s<br>', $times[0], $times[1], $instance->calculate()); } echo '</pre>'; is it possible that the output automatically like this: 192.27 2022-04-11 16:05:00 | 2022-04-11 18:00:00 | 168.67 2022-04-11 18:00:00 | 2022-04-11 18:12:00 | 23.60 -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
Thanks for your reply Barand, pls ignore above information, my mistake. is it possible to add calculating summary in script? -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
amending -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
imagine that you go rental a table. from Friday 12:00 to Saturday 12:00 = total 24 hours. so should be = $88(weekday 1200-1800) *6 + $118(weekday 1800-0000) *6 + $128(weekend 0000-0200) *2+ $98(weekend 0200-1800) *10 = $2,472 time different price calc as below. $week_day = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']; $weekend_day = ['Sat', 'Sun']; $price_weekday_hour = 88; // weekday 0200-1800 $price_weekday_peakhour = 118; // weekday 1800-0200 $price_weekend_hour = 98; // weekend 0200-1800 $price_weekend_peakhour = 128; // weekend 1800-0200 -
PHP calc price with different time range cost
kit123321 replied to kit123321's topic in PHP Coding Help
just tested, calc result not correct. the correct count for below time1,time2, should be = 588+128 = $716