<br><br><br><br>
<div class="card" id="primary-card">
    <div class="card-header ui-sortable-handle" style="cursor: move">
        <h1 class="card-title" style="font-size: 2rem;" id='totalbettitle30days'>Total Bet Amounts and Prizes for the Last 30 Days (Only Me)</h1>
        <div class="card-tools">
        </div>
    </div>
    <div class="card-body ">
        <br><br>
        <table id="MonthlyBetAmountsandPrizesTable">
            <thead>
                <th>Date</th>
                <th> Bet Amount</th>
                <th>Prizes</th>
            </thead>
            <tbody>
            </tbody>


        </table>
Total Bet Amount: <h4 id="Last30DaysTotalBetAmount"></h4>
Total Prizes Amount: <h4 id="Last30DaysTotalPrizesAmount"></h4>


    </div>
</div>
<br><br><br>

<script>

    function GenerateBetAmountPrizes30DaysRow(Date, Bet_Amount, Prize) {


        return `<tr>
      <td>${Date}</td>
      <td>${Bet_Amount}</td>
      <td>${Prize}</td>
  </tr>`;
    }

    


    async function GenerateBetAmountPrizeTodayRows(responsearray) {
    //    console.log(responsearray);
        let newhtmltable = '';
        let totalbetamount = 0;
        let totalprizes = 0;

        for (let i = 0; i < responsearray.length; i++) {
            totalbetamount += responsearray[i]['total_bet_amount'];
            totalprizes += responsearray[i]['total_prizes'];
            newhtmltable += GenerateBetAmountPrizes30DaysRow(
                responsearray[i]['date'],
                responsearray[i]['total_bet_amount'],
                responsearray[i]['total_prizes']
            );
        }

        //$("#User_list_table").find("tbody").replaceWith(newhtmltable);
        // new DataTable('#User_list_table');


        $("#MonthlyBetAmountsandPrizesTable").find("tbody").html(newhtmltable);
        $("#Last30DaysTotalBetAmount").html(totalbetamount);
        $("#Last30DaysTotalPrizesAmount").html(totalprizes);

        new DataTable('#MonthlyBetAmountsandPrizesTable', {
            language: {
                emptyTable: 'No Data Loaded'
            },
            order: [[0, 'desc']],
            "bDestroy": true
        });





    }


    function GenerateBetAmountsAndPrizes30DaysTable() {
let onlyme;

        if (typeof currenttarget === 'object' && currenttarget.hasOwnProperty('onlyme')) {
            onlyme = currenttarget['onlyme'];
        }

        if (typeof currenttarget === 'object' && currenttarget.hasOwnProperty('currenttarget')) {
            currenttarget = currenttarget['currenttarget'];
        }
   
    
        if (onlyme) {
    document.getElementById('totalbettitle30days').innerHTML = 'Total Bet Amounts and Prizes for the Last 30 Days (Only Me)';
} else {
    document.getElementById('totalbettitle30days').innerHTML = 'Total Bet Amounts and Prizes for the Last 30 Days (Me and All Users Under Me)';
}
        AjaxDo('?admin/reports/TotalBetsPrizes/Last30Days', { targetuser: currenttarget, onlyme:  onlyme}, GenerateBetAmountPrizeTodayRows, null, reqtype = 'POST');
  
    }



    GenerateBetAmountsAndPrizes30DaysTable();

    setInterval(function () {
        if (currentPage == 'BetAmountsAndPrizes30Days ') {
            GenerateBetAmountsAndPrizes30DaysTable();
        }
    }, 300000);

    $( document ).ready(function() {

    });

   
  

</script>