Jump to content

Barand

Moderators
  • Posts

    24,604
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. Looking at the code you posted it looks you have decided to ignore the rules of syntax for inline style definitions and class specifications. Plus a bit of obsolete html markup thrown in for good measure
  2. Haven't we been here before?
  3. Here's my attempt SELECT sale_date , sum(cashpaid) + sum(cashpartpaid) + sum(codpaid) as total_cash_sales , sum(cashdue) + sum(cashpartdue) + sum(carddue) + sum(coddue) as total_credit_sales , sum(codpaid) + sum(coddue) as total_cod_sales , sum(cardpaid) as total_card_sales FROM ( SELECT bad.basket_id , bad.amount_due as due , SUM(p.amount_paid) as paid , p.payment_method_id , b.payment_status , DATE(bad.sale_time) as sale_date , CASE WHEN payment_method_id = 1 AND payment_status = 'paid' THEN sum(p.amount_paid) ELSE 0 END as cashpaid , CASE WHEN payment_method_id = 1 AND payment_status = 'due' THEN bad.amount_due ELSE 0 END as cashdue , CASE WHEN payment_method_id = 1 AND payment_status = 'partial' THEN SUM(p.amount_paid) ELSE 0 END as cashpartpaid , CASE WHEN payment_method_id = 1 AND payment_status = 'partial' THEN bad.amount_due - SUM(p.amount_paid) ELSE 0 END as cashpartdue , CASE WHEN payment_method_id = 2 THEN SUM(p.amount_paid) ELSE 0 END as cardpaid , CASE WHEN payment_method_id = 2 THEN bad.amount_due - SUM(p.amount_paid) ELSE 0 END as carddue , CASE WHEN payment_method_id = 4 AND payment_status <> 'due' THEN SUM(p.amount_paid) ELSE 0 END as codpaid , CASE WHEN payment_method_id = 4 AND payment_status = 'due' THEN bad.amount_due ELSE 0 END as coddue FROM basket_amount_due bad JOIN basket b USING (basket_id) LEFT JOIN basket_payment p USING (basket_id) GROUP BY basket_id, payment_method_id ) detail GROUP BY sale_date;
  4. Or you could do at the source when you query your data. SELECT Firstname , Lastname , Coursename , CASE WHEN DateBooked IS NULL THEN '' ELSE DATE_FORMAT(DateBooked, '%d-%m-%Y') END as DateBooked, , DATE_FORMAT(ExpiryDate, '%d-%m-%Y') as ExpirtyDate , Notes FROM ....
  5. I think you'll find they were mentioned a little earlier than that ... ... and I doubt that is the earliest.
  6. Your payment status values are "Paid/Due/Partial" Do we have a couple of new Schrodinger cats in your latest calculation requirements...
  7. Is it correct that some combinations of method/status should be included in more than one total?
  8. If I were showing totals by "Payment method" I would find it helpful to show the method descriptions in the row output. The main question - is that correct and what you wanted?
  9. Given the adage "Test data is that data for which the code works", here is the data I used for the queries I posted
  10. None of those have a value of both 1 AND 2. That would mean, like Schrodinger's cat, they have two values at the same time, Some, though, do have a value of 1 OR 2
  11. Firstly, can you show me the record where the "payment_method_id" is both 1 and 2 ? You to need to change around the syntax of that first CASE statement , CASE WHEN p.payment_method_id IN (1, 2) THEN sum(amount_due) ELSE 0 END AS total_cash_sales = where date on or after today but before tomorrow. Isn't that just WHERE DATE(bv.sale_time) = CURDATE() Lastly, are you sure you want to GROUP BY sale_time? That gives you a total for each second, which is probably individual sales - not much of a summary.
  12. My money's on "Syntax error". (Error 4)
  13. This fails $j = "{'admin': 1, 'moderator': 1}" ; $a = json_decode($j, 1); echo '<pre> a ' . print_r($a, 1) . '</pre>'; This works $j = '{"admin": 1, "moderator": 1}' ; $b = json_decode($j, 1); echo '<pre> b ' . print_r($b, 1) . '</pre>'; Note the quotes in the JSON string.
  14. Doesn't your console have a "preserve" option? Or, add "return false" to the end of your submitData() function to stop the page refreshing
  15. How do you define "does not work"? Because when I use your form and the first function, my console shows the data entered in the form
  16. $expression2 = [ "type" => "add", 'children' => [ [ "type" => "number", "value" => 100 // $expression2['children'][0]['value'] ], [ "type" => "multiply", "children" => [ [ "type" => "number", "value" => 2 // $expression2['children'][1]['children'][0]['value'] ], [ "type" => "add", "children" => [ [ "type" => "number", "value" => 5 // $expression2['children'][1]['children'][1]['children'][0]['value'] ], [ "type" => "number", "value" => 45 // $expression2['children'][1]['children'][1]['children'][1]['value'] ] ] ] ] ] ] ]; It's easier if you do a print_r() of the array so you see all the indexes echo '<pre>$expression2 = ' . print_r($expression2, 1) . '</pre>'; then follow the indexes down the tree .... showing the path for echo $expression2['children'][1]['children'][1]['children'][1]['value']; // 45
  17. Never store data with multiple values like this '$week_ending', '$staff_name', '$monday_start', '$monday_finish', '$tuesday_start', '$tuesday_finish', '$wednesday_start', '$wednesday_finish', '$thursday_start', '$thursday_finish', '$friday_start', '$friday_finish', '$saturday_start', '$saturday_finish', '$sunday_start', '$sunday_finish', '$total_hours', '$timesheet_comment' You should always normalize your data when using an RDBMS. Once that's done, the processing can become a whole lot simpler. For example, if you table were like this... TABLE: driver TABLE: driver_timesheet +-----------+-----------+----------+ +--------------+-----------+-------------+-------------------+ | driver_id | firstname | lastname | | timesheet_id | driver_id | week_ending | timesheet_comment | +-----------+-----------+----------+ +--------------+-----------+-------------+-------------------+ | 1 | Peter | Dowt | | 1 | 1 | 2021-09-05 | 4-day week | | 2 | Laura | Norder | ----------------------------------------------------------------< | 2 | 2 | 2021-09-05 | No Saturday work | | 3 | Tom | DiCanari | | 3 | 3 | 2021-09-05 | No Sunday work | +-----------+-----------+----------+ +--------------+-----------+-------------+-------------------+ | | +------------------------------------------------------------------------------------+ TABLE: driver_time | +----------------+--------------+-------------+------------+----------+------------+ | driver_time_id | timesheet_id | driver_date | time_start | time_end | break_time | +----------------+--------------+-------------+------------+----------+------------+ | 1 | 1 | 2021-08-30 | 08:15:00 | 18:05:00 | 01:20:00 | | 2 | 1 | 2021-08-31 | 08:30:00 | 17:35:00 | 01:10:00 | | 3 | 1 | 2021-09-01 | 08:20:00 | 18:00:00 | 01:00:00 | | 4 | 1 | 2021-09-05 | 08:00:00 | 17:55:00 | 01:10:00 | | 19 | 2 | 2021-08-30 | 08:16:00 | 17:17:00 | 01:19:00 | | 20 | 2 | 2021-08-31 | 08:19:00 | 17:25:00 | 01:06:00 | | 21 | 2 | 2021-09-01 | 08:18:00 | 17:41:00 | 01:24:00 | | 22 | 2 | 2021-09-02 | 08:07:00 | 17:26:00 | 01:20:00 | | 23 | 2 | 2021-09-03 | 08:09:00 | 17:21:00 | 01:01:00 | | 25 | 2 | 2021-09-05 | 08:06:00 | 17:46:00 | 01:24:00 | | 26 | 3 | 2021-08-30 | 08:23:00 | 17:38:00 | 01:02:00 | | 27 | 3 | 2021-08-31 | 08:04:00 | 17:23:00 | 01:21:00 | | 28 | 3 | 2021-09-01 | 08:21:00 | 17:30:00 | 01:13:00 | | 29 | 3 | 2021-09-02 | 08:22:00 | 17:36:00 | 01:01:00 | | 30 | 3 | 2021-09-03 | 08:23:00 | 17:32:00 | 01:09:00 | | 31 | 3 | 2021-09-04 | 08:21:00 | 17:05:00 | 01:00:00 | +----------------+--------------+-------------+------------+----------+------------+ then all you need to do is write the data from your input form to the tables. To get the daily hours worked ... SELECT concat(firstname,' ', lastname) as name , dayname(driver_date) as day , date_format(driver_date, '%b %d') as date , time_start , time_end , break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM driver_time JOIN driver_timesheet USING (timesheet_id) JOIN driver USING (driver_id) WHERE week_ending = '2021-09-05' ORDER BY driver_id, driver_date; +--------------+-----------+--------+------------+----------+------------+------------+ | name | day | date | time_start | time_end | break_time | hrs_worked | +--------------+-----------+--------+------------+----------+------------+------------+ | Peter Dowt | Monday | Aug 30 | 08:15:00 | 18:05:00 | 01:20:00 | 08:30:00 | | Peter Dowt | Tuesday | Aug 31 | 08:30:00 | 17:35:00 | 01:10:00 | 07:55:00 | | Peter Dowt | Wednesday | Sep 01 | 08:20:00 | 18:00:00 | 01:00:00 | 08:40:00 | | Peter Dowt | Sunday | Sep 05 | 08:00:00 | 17:55:00 | 01:10:00 | 08:45:00 | | Laura Norder | Monday | Aug 30 | 08:16:00 | 17:17:00 | 01:19:00 | 07:42:00 | | Laura Norder | Tuesday | Aug 31 | 08:19:00 | 17:25:00 | 01:06:00 | 08:00:00 | | Laura Norder | Wednesday | Sep 01 | 08:18:00 | 17:41:00 | 01:24:00 | 07:59:00 | | Laura Norder | Thursday | Sep 02 | 08:07:00 | 17:26:00 | 01:20:00 | 07:59:00 | | Laura Norder | Friday | Sep 03 | 08:09:00 | 17:21:00 | 01:01:00 | 08:11:00 | | Laura Norder | Sunday | Sep 05 | 08:06:00 | 17:46:00 | 01:24:00 | 08:16:00 | | Tom DiCanari | Monday | Aug 30 | 08:23:00 | 17:38:00 | 01:02:00 | 08:13:00 | | Tom DiCanari | Tuesday | Aug 31 | 08:04:00 | 17:23:00 | 01:21:00 | 07:58:00 | | Tom DiCanari | Wednesday | Sep 01 | 08:21:00 | 17:30:00 | 01:13:00 | 07:56:00 | | Tom DiCanari | Thursday | Sep 02 | 08:22:00 | 17:36:00 | 01:01:00 | 08:13:00 | | Tom DiCanari | Friday | Sep 03 | 08:23:00 | 17:32:00 | 01:09:00 | 08:00:00 | | Tom DiCanari | Saturday | Sep 04 | 08:21:00 | 17:05:00 | 01:00:00 | 07:44:00 | +--------------+-----------+--------+------------+----------+------------+------------+ and to get the weekly hours for each driver for payroll ... SELECT date_format(week_ending, '%d %b %Y') as wk_ending , concat(firstname,' ', lastname) as name , round(sum(time_to_sec( timediff(timediff(time_end, time_start), break_time) ))/3600, 2) as tot_hrs_dec FROM driver_time JOIN driver_timesheet USING (timesheet_id) JOIN driver USING (driver_id) WHERE week_ending = '2021-09-05' GROUP BY week_ending, driver_id +-------------+--------------+-------------+ | wk_ending | name | tot_hrs_dec | +-------------+--------------+-------------+ | 05 Sep 2021 | Peter Dowt | 33.83 | | 05 Sep 2021 | Laura Norder | 48.12 | | 05 Sep 2021 | Tom DiCanari | 48.07 | +-------------+--------------+-------------+ All your calculations done with a couple of queries.
  18. NOTE: the win_percentage in $win = percent_win(20); ^^ (100 / $odds) should be equal to 100/$odds
  19. Yes. So in answer to your 60% question... If you have an array of 10 elements and 6 of them are 1's, there is a 60% chance of selecting a 1. $win = percent_win(60); // $win will be 1 (true) approx 60% of the time function percent_win($pc) { $lose = 100 - $pc; $a1 = array_fill(0, $lose, 0); $a2 = array_fill(0, $pc, 1); $a1 = array_merge($a1, $a2); shuffle($a1); return $a1[array_rand($a1)]; } To test... $w = $l = 0; for ($i=0; $i<1000; $i++) { $win = percent_win(20); if ($win) ++$w; else ++$l; } printf ('%d - %d - %0.3f', $w, $l, $w/($w + $l) );
  20. @ginerjm That was my argument too, but I relented when I ran the simulation over 500 runs If I took out the - $bet from a winning payout (so you weren't losing your stake money) but keeping the odds = 2 and the chance of win = rand(0, 1) then the accumulated bankroll would have made Elon Musk green with envy. EG Thinking about it, the odds of winning are even but you are being paid out at 2-1. So not surprising the gains are exponential. To get it back on an even keel I then changed the chance of a win to $win = rand(0, $odds)==1 so the chance matched the odds. Going back to the original method I decided was a matter of interpretation. The OP's odds of "2", I guess, is actually 1 in 2 (evens) so the OP's formaula works if the stake is lost but double is paid back.
  21. I still have no idea what you mean by "PROFIT for each winning unit"
  22. Define "unit". Count the wins, multiply by 100 and divide by number of bets (which may be less than 500 if you run out of funds).
  23. Something like this? <?php const BETS = 500; $bankroll = 500; $pcent = 0.1; $odds = 2; function betting(&$bankroll, $betPerc, $odds) { for ($i=1; $i <= BETS; $i++) { if ($bankroll < 0.5) break; $win = rand(0,1); $bet = $bankroll * $betPerc; $bankroll += ($win ? $bet * $odds - $bet : - $bet); printf("| %3d | %20.2f | %s | %20s |<br>", $i, $bet, $win ? '&check;' : '&times;', number_format($bankroll,2)); } } echo '<pre>'; printf("| %54.2f |<br>", $bankroll); betting($bankroll, $pcent, $odds); ?>
  24. No - in that case you have won your bet but still lost your 50.00 stake. If you lose you pay them If you win, they pay you You are doing both at the same time
  25. But if you win, you get your stake back + winnings.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.