<?php 
//UPDATE USER CURRENCY =======================================================================================================
if(isset($_REQUEST['submit_cur_change'])){
        if($bankdata->change_currency($_REQUEST['selected_cur'],adminurl)){
          // print_r($_REQUEST['selected_cur']);
          echo "
          <script>
          Swal.fire({
          icon: 'success',
          title: 'Congratulations',
          text: 'New Currency Selected!',
        })
        </script> 
          ";
       }else{
         echo "
         <script>
         Swal.fire({
         icon: 'error',
         title: 'Oops',
         text: 'Unable to Select Currency',
       })
       </script> 
         ";

        }
        }
//CREAT TRANSACTION CODES =======================================================================================================
if(isset($_REQUEST['create_code'])){
        if($bankdata->create_transaction_code($_REQUEST,adminurl)){
          echo "
          <script>
          Swal.fire({
          icon: 'success',
          title: 'Congratulations',
          text: 'New Code Added!',
        })
        </script> 
          ";
       }else{
         echo "
         <script>
         Swal.fire({
         icon: 'error',
         title: 'Oops',
         text: 'Unable to Add New code',
       })
       </script> 
         ";

        }
        }
//UPDATE USER DATA =======================================================================================================
if(isset($_REQUEST['update_info'])){
        if($bankdata->update_user($_REQUEST,adminurl)){
          echo "
          <script>
          Swal.fire({
          icon: 'success',
          title: 'Congratulations',
          text: 'Info Updated Successfully!',
        })
        </script> 
          ";
       }else{
         echo "
         <script>
         Swal.fire({
         icon: 'error',
         title: 'Oops',
         text: 'Unable to Update Info',
       })
       </script> 
         ";

        }
        }

//DELETE TRANSACTION  =======================================================================================================
if(isset($_REQUEST['delete_transaction'])){
        if($bankdata->delete_transaction($_REQUEST['delete_transaction'],false,$_REQUEST['amount'],$_REQUEST['type'],adminurl)){
          // print_r($_REQUEST['selected_cur']);
          echo "
          <script>
          Swal.fire({
          icon: 'success',
          title: 'Congratulations',
          text: 'Transaction Deleted Successfully!',
        })
        </script> 
          ";
       }else{
         echo "
         <script>
         Swal.fire({
         icon: 'error',
         title: 'Oops',
         text: 'Unable to Delete Transaction!',
       })
       </script> 
         ";

        }
        }
//DELETE TRANSACTION CODES  =======================================================================================================
if(isset($_REQUEST['delete_transaction_codes'])){
        if($bankdata->delete_transaction_codes($_REQUEST['delete_transaction_codes'])){
          // print_r($_REQUEST['selected_cur']);
          echo "
          <script>
          Swal.fire({
          icon: 'success',
          title: 'Congratulations',
          text: 'Transaction Deleted Successfully!',
        })
        </script> 
          ";
       }else{
         echo "
         <script>
         Swal.fire({
         icon: 'error',
         title: 'Oops',
         text: 'Unable to Delete Transaction!',
       })
       </script> 
         ";

        }
        }
//UPDATE TRANSACTIONS STATUS ================================================================================================

if(isset($_POST['updateStat'])){
  if($_POST['transfer_stat_val'] == 'success'){
//   if($bankdata->update_funds(adminurl,intval($bankdata->get_balance(adminurl)) - intval($_POST['trnsamt']))){
    if($bankdata->update_transaction($_POST['transaction_id'],'success')){
      echo "<script>Swal.fire({
        icon: 'success',
        title: 'Congratulations',
        text: 'Account Updated successfully!',
      })</script>";
    }else{
      echo "<script>Swal.fire({
        icon: 'error',
        title: 'Error',
        text: 'Account Update failed!',
      })</script>";
    }
//   }
  }else{
    if($bankdata->update_transaction($_POST['transaction_id'],$_POST['transfer_stat_val'])){
      echo "<script>Swal.fire({
        icon: 'success',
        title: 'Congratulations',
        text: 'Account Updated successfully!',
      })</script>";
    }else{
      echo "<script>Swal.fire({
        icon: 'error',
        title: 'Error',
        text: 'Account Update failed!',
      })</script>";
    }
  }
}

//UPDATE TRANSACTION DATE =================================================================================
if(isset($_POST['updateDate'])){
  if($bankdata->update_date($_POST['transaction_id'],$_POST['newdate'])){
      echo "<script>Swal.fire({
        icon: 'success',
        title: 'Congratulations',
        text: 'Account Updated successfully!',
      })</script>";
    }else{
      echo "<script>Swal.fire({
        icon: 'error',
        title: 'Error',
        text: 'Account Update failed!',
      })</script>";
    }
  }
?> 


<?php

//UPDATE ACCOUNT STATUS===========================================================================
if(isset($_POST['updateStats'])){
  $acct_number = adminurl;
  $stat_data = $_POST['stat_data'];

                      if($stat_data == 'active'){
                        $stat_data = 'inactive';
                      }else{
                        $stat_data = 'active';
                      }
                      
  if($bankdata->acct_stats_func($acct_number,$stat_data)){
    echo "
    <script>
    Swal.fire({
    icon: 'success',
    title: 'Congratulations',
    text: 'Account Status Updated Successfully!',
  })
  </script> 
    ";
  }else{
    echo "
    <script>
    Swal.fire({
    icon: 'error',
    title: 'Oops',
    text: 'Unable to update Account Status, try again later',
  })
  </script> 
    ";
  }


}
//CREDIT AND DEBIT ACCOUNT BALANCE===================================================================================
if(isset($_POST['credit_account'])){
    $acct_number = adminurl;
    $amount = $_POST['credit_amount'];
    $desc = $_POST['credit_desc'];
    $date = $_POST['credit_created_date'];
    $type = 'credit';
    $bn_bank = 'Bank';
    $bn_accno = $_POST['credit_bn_accno'];
    $bn_name = $_POST['credit_bn_name'];

  if($bankdata->update_funds_new($acct_number,$type,$amount,$desc,$date,$bn_name,$bn_bank,$bn_accno)){
    echo "
    <script>
    Swal.fire({
    icon: 'success',
    title: 'Congratulations',
    text: 'Balance Credited Successfully!',
  })
  </script> 
    ";
 }else{
   echo "
   <script>
   Swal.fire({
   icon: 'error',
   title: 'Oops',
   text: 'Unable to Credit balance, try again later',
 })
 </script> 
   ";
 }  
}

if(isset($_POST['debit_account'])){
    $acct_number = adminurl;
    $amount = $_POST['debit_amount'];
    $desc = $_POST['debit_desc'];
    $date = $_POST['debit_created_date'];
    $type = 'debit';
    $bn_bank = 'Bank';
    $bn_accno = $_POST['debit_bn_accno'];
    $bn_name = $_POST['debit_bn_name'];

  if($bankdata->update_funds_new($acct_number,$type,$amount,$desc,$date,$bn_name,$bn_bank,$bn_accno)){
    echo "
    <script>
    Swal.fire({
    icon: 'success',
    title: 'Congratulations',
    text: 'Balance Debited Successfully!',
  })
  </script> 
    ";
 }else{
   echo "
   <script>
   Swal.fire({
   icon: 'error',
   title: 'Oops',
   text: 'Unable to Debit balance, try again later',
 })
 </script> 
   ";
 }
  }
  $singleClient = $bankdata->get_acct_data(adminurl)[0];
?>

<div class="content-wrapper">
    <div class="row">
            <div class="col-md-12 grid-margin">
              <div class="d-flex justify-content-between flex-wrap">
                <div class="d-flex align-items-end flex-wrap">
                  <div class="me-md-3 me-xl-5">
                    <h2><?php echo $singleClient['acct_name']; ?>'s Profile</h2>
                  </div>
                </div>
                <!--<div class="d-flex justify-content-between align-items-end flex-wrap">-->
                <!--  <a href="#history" class="btn btn-primary mt-2 mt-xl-0"> <i class="mdi mdi-history text-muted"></i> Transaction history</a>-->
                <!--</div>-->
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-md-12 grid-margin stretch-card">
              <div class="card">
                <div class="card-body dashboard-tabs p-0">
                  <ul class="nav nav-tabs px-4" role="tablist">
                    <li class="nav-item">
                      <a class="nav-link active" id="overview-tab" data-bs-toggle="tab" href="#overview" role="tab" aria-controls="overview" aria-selected="true">Overview</a>
                    </li>
                  </ul>
                  <div class="tab-content py-0 px-0">
                    <div class="tab-pane fade show active" id="overview" role="tabpanel" aria-labelledby="overview-tab">
                      <div class="d-flex flex-wrap justify-content-xl-between">
                        <div class="d-none d-xl-flex border-md-right flex-grow-1 align-items-center justify-content-center p-3 item">
                          <i class="mdi mdi-calendar-heart icon-lg me-3 text-primary"></i>
                          <div class="d-flex flex-column justify-content-around">
                            <small class="mb-1 text-muted">Start date</small>
                            <div class="dropdown">
                              <a class="btn btn-secondary p-0 bg-transparent border-0 text-dark shadow-none font-weight-medium">
                                <h5 class="mb-0 d-inline-block"><?php echo format_d_date_full($singleClient['created_at']); ?></h5>
                              </a>
                            </div>
                          </div>
                        </div>
                        <div class="d-flex border-md-right flex-grow-1 align-items-center justify-content-center p-3 item">
                          <i class="mdi mdi-currency-usd me-3 icon-lg text-danger"></i>
                          <div class="d-flex flex-column justify-content-around">
                            <small class="mb-1 text-muted">Main Balance</small>
                            <h5 class="me-2 mb-0"><?php echo $singleClient['active_currency'].number_format($singleClient['checking_balance'],2); ?></h5>
                          </div>
                        </div>
                        <div class="d-flex border-md-right flex-grow-1 align-items-center justify-content-center p-3 item">
                          <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" class="" method="POST">
        <div class="form-group">
          <label>Select Currency</label>
                    <div class="input-group">
                         <div class="input-group-prepend">
                        <span class="input-group-text" id="selected_currency"><?php echo $singleClient['active_currency']; ?></span>
                      </div>
                  <select class="form-control form-control-sm" name="selected_cur" id="" required>
                  <option value="" <?php echo ($singleClient['active_currency']=='')?'selected':''; ?>>Select</option>
                    <option value="&#8364;" <?php echo ($singleClient['active_currency']=='&#8364;')?'selected':''; ?>>Euro</option>
                    <option value="&#163;" <?php echo ($singleClient['active_currency']=='&#163;')?'selected':''; ?>>Pounds sterling</option>
                    <option value="&#36;" <?php echo ($singleClient['active_currency']=='&#36;')?'selected':''; ?>>United States Dollar</option>
                    <option value="&yen" <?php echo ($singleClient['active_currency']=='&yen;')?'selected':''; ?>>Chinese yuan</option>	
                  </select>
                      <div class="input-group-append">
                        <button class="btn btn-sm btn-primary" type="submit" name="submit_cur_change"  onclick="">Change Currency</button>
                      </div>
                      
                    </div>
                  </div>
            </form>
                        </div>
                        <div class="d-flex border-md-right flex-grow-1 align-items-center justify-content-center p-3 item">
                      <form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>" class="w-100 p-0 m-0">
                      <div class="form-group">
                    <div class="input-group">
                    <?php
                      if($bankdata->acct_stats_func($singleClient['acct_number']) == 'active'){
                        echo '<span class="badge badge-success">'.$bankdata->acct_stats_func($singleClient['acct_number']).'</span>';
                      }else{
                        echo '<span class="badge badge-danger">'.$bankdata->acct_stats_func($singleClient['acct_number']).'</span>';
                      }
                      ?>
                    <input type="hidden" class="form-control" name="stat_data" value="<?php echo $bankdata->acct_stats_func($singleClient['acct_number']); ?>">
                    <input type="hidden" class="form-control" name="acct_number" value="<?php echo $singleClient['acct_number']; ?>">
                      <div class="input-group-append">
                        <button class="btn btn-sm btn-primary" type="submit" name="updateStats">Make <?php 
                        if($bankdata->acct_stats_func($singleClient['acct_number']) == 'active'){
                          echo 'Inactive!';
                        }else{
                          echo 'Active!';
                        }
                        ?></button>
                      </div>
                      
                    </div>
                  </div>
                  </form>
                        </div>
                        <div class="d-flex border-md-right flex-grow-1 align-items-center justify-content-center p-3 item">
                                <form method="delete" action="/admin/client_list">
                        <button type="submit" name="delete_acct_number" value="<?php echo $singleClient['acct_number']; ?>" class="btn btn-danger btn-rounded btn-icon">
                            <i class="mdi mdi-trash-can"></i>
                      </button>
                      </form>
                        </div>
                      </div>
                    </div>
                
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="row d-flex justify-content-center">
          <div class="col-md-6 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <h4 class="card-title">Client Data</h4>
                  <div class="w-100 d-flex justify-content-center py-3">
                    <img src="/img/upload/<?php echo $singleClient['passport_photo']; ?>" class="w-25 h-25 rounded-circle">
                  </div>
                  <div class="forms-sample">
                    <div class="form-group col-12">
                      <label for="">Name</label>
                      <input type="text" class="form-control" value="<?php echo $singleClient['acct_name']; ?>" readonly>
                    </div>
                    <div class="form-group col-12">
                      <label for="">Email</label>
                      <input type="text" class="form-control" value="<?php echo $singleClient['acct_email']; ?>" readonly>
                    </div>
                    <div class="form-group col-12">
                      <label for="">Account Number</label>
                      <input type="text" class="form-control" value="<?php echo $singleClient['acct_number']; ?>" readonly>
                    </div>
                    <div class="form-group col-12">
                      <label for="">Account Password</label>
                      <input type="text" class="form-control" value="<?php echo $singleClient['acct_password_unhash']; ?>" readonly>
                    </div>
                    <form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
                    <div class="form-group col-12">
                      <label for="transfer_code">Change Login Pin:</label>
                      <input type="text" class="form-control" id="transfer_code" name="transfer_code" value="<?php echo $singleClient['transfer_code']; ?>" placeholder="XXXX" required>
                    </div>
                    
                    <div class="form-group col-12">
                      <label for="">Mobile</label>
                        <input type="text" class="form-control" name="acct_phone" value="<?php echo $singleClient['acct_phone']; ?>" required>
                    </div>
                    <div class="form-group col-12">
                      <label for="nok_name">Next of Kin's Name:</label>
                      <input type="text" class="form-control" id="nok_name" name="nok_name" value="<?php echo $singleClient['nok_name']; ?>" placeholder="Next of Kin's Name" required>
                    </div>
                    <div class="form-group col-12">
                      <label for="nok_phone">Next of Kin's Phone:</label>
                      <input type="text" class="form-control" id="nok_phone" name="nok_phone" value="<?php echo $singleClient['nok_phone']; ?>" placeholder="Next of Kin's Phone Number" required>
                    </div>
                    
                    <h4>Transaction Status</h4>
                    <hr>
                    <div class="form-check form-check-success">
                            <label class="form-check-label">
                              <input type="radio" class="form-check-input" value="success" name="transaction_status" id="ExampleRadio2" <?php echo ($singleClient['transaction_status']=='success')?'checked':''; ?> required>
                              Transaction Successful
                            </label>
                          </div>
                          <div class="form-check form-check-info">
                            <label class="form-check-label">
                              <input type="radio" class="form-check-input" value="pending" name="transaction_status" id="ExampleRadio3" <?php echo ($singleClient['transaction_status']=='pending')?'checked':''; ?> required>
                              Transaction Pending
                            </label>
                          </div>
                          <div class="form-check form-check-danger">
                            <label class="form-check-label">
                              <input type="radio" class="form-check-input" value="failed" name="transaction_status" id="ExampleRadio4" <?php echo ($singleClient['transaction_status']=='failed')?'checked':''; ?> required>
                              Transaction Failed
                            </label>
                          </div>
                          <div class="form-check form-check-secondary">
                            <label class="form-check-label">
                              <input type="radio" class="form-check-input" value="limit" name="transaction_status" id="ExampleRadio5" <?php echo ($singleClient['transaction_status']=='limit')?'checked':''; ?> required>
                              Transaction Limit
                            </label>
                          </div>
                          <hr>
                         <div class="form-group">
                            <label>Transaction Message</label>
                            <textarea class="form-control" name="message" id="transaction_message" rows="3" style="resize: vertical;line-height: 1.5em;line-spacing:1.5em" required><?php echo $singleClient['message']; ?></textarea>
                        </div>
                      <button type="submit" name="update_info" class="btn btn-primary w-100"> <i class="mdi mdi-arrow-up"></i> Update Info</button>
                      </form>
                  </div>
                </div>
              </div>
            </div>
             <div class="col-md-6 grid-margin stretch-card">
                 <div class="row">
                     <div class="col-12">
                         
                     
                 <div class="card">
                <div class="card-body">
                  <h4 class="card-title">Credit Account</h4>
                  <form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>" class="w-100 p-0 m-0">
                  <div class="forms-sample">
                    <div class="form-group col-12">
                      <label>Transaction Type</label>
                      <input type="text" class="form-control" value="Credit" readonly>
                    </div>
                    <div class="form-group col-12">
                      <label>Amount</label>
                    <input type="number" class="form-control" name="credit_amount" onkeyup="generateRandomName('credit')" id="credit_amount" value="0" required>
                    <input type="hidden" class="form-control" name="credit_bn_name"  id="credit_bn_name" value="0" required>
                    <input type="hidden" class="form-control" name="credit_bn_accno"  id="credit_bn_accno" value="0" required>
                  </div>
                  <div class="form-group col-12">
                      <label>Transaction Date</label>
                    <input type="datetime-local" class="form-control" name="credit_created_date" value="<?php echo date('Y-m-d H:i:s'); ?>" required>
                  </div>
                  <div class="form-group col-12">
          <label>Transfer Description</label>
                  <textarea class="form-control" name="credit_desc" id="trans_desc_credit" rows="3" style="resize: vertical;line-height: 1.5em;line-spacing:1.5em" required></textarea>
                   </div>
                      <div class="form-group">
                        <button class="btn btn-sm btn-secondary" type="button" name=""  onclick="generateRandomName('credit')">Generate Names</button>
                      </div>
               <button class="btn btn-success w-100" type="submit" name="credit_account" value="submit">Credit Account</button>

                  
</div>
</form>
</div>
</div>

</div>
                 <div class="col-12">
                 <div class="card">
                <div class="card-body">
                  <h4 class="card-title">Debit Account</h4>
                  <form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>" class="w-100 p-0 m-0">
                  <div class="forms-sample">
                    <div class="form-group col-12">
                      <label>Transaction Type</label>
                      <input type="text" class="form-control" value="Debit" readonly>
                    </div>
                    <div class="form-group col-12">
                      <label>Amount</label>
                    <input type="number" class="form-control" onkeyup="generateRandomName('debit')" name="debit_amount" id="debit_amount" value="0" required>
                    <input type="hidden" class="form-control" name="debit_bn_name"  id="debit_bn_name" value="0" required>
                    <input type="hidden" class="form-control" name="debit_bn_accno"  id="debit_bn_accno" value="0" required>
                  </div>
                  <div class="form-group col-12">
                      <label>Transaction Date</label>
                    <input type="datetime-local" class="form-control" name="debit_created_date" value="<?php echo date('Y-m-d H:i:s'); ?>" required>
                  </div>
                  <div class="form-group col-12">
          <label>Transfer Description</label>
                  <textarea class="form-control" name="debit_desc" id="trans_desc_debit" rows="3" style="resize: vertical;line-height: 1.5em;line-spacing:1.5em" required></textarea>
                   </div>
                      <div class="form-group">
                        <button class="btn btn-sm btn-secondary" type="button" name=""  onclick="generateRandomName('debit')">Generate Names</button>
                      </div>
               <button class="btn btn-danger w-100" type="submit" name="debit_account" value="submit">Debit Account</button>

                  
</div>
</form>
</div>
</div></div></div>
                    </div>
                </div>
          <div class="row">
            <div class="col-lg-12 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <h4 class="card-title">Tansaction Codes</h4>
                  <div class="table-responsive">
                    <table class="table">
                      <thead>
                        <tr>
                          <th>Name</th>
                          <th>Codes</th>
                          <th>Instruction</th>
                          <th>Date Created</th>
                          <th>Status</th>
                          <th>Action</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
          $allacct = $bankdata->get_transact_code(adminurl);
          foreach($allacct as $allXacct){
                        ?><tr>
                          <td><?php echo $allXacct['name']; ?> 
                        </td>
                          <td><?php echo $allXacct['codes']; ?>
                        </td>
                          <td>
                              <?php echo $allXacct['instruction']; ?>    
                        </td>
                          <td>
                            <?php echo format_d_date_full($allXacct['created_at']); ?>
                        </td>
                        <td>
                            <?php if($allXacct['used'] == true){echo '<span class="badge badge-danger">used</span>';}else{ echo '<span class="badge badge-success">unused</span>';} ?>
                        </td>
                        <td>
                  <form method="delete" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
                        <button type="submit" name="delete_transaction_codes" value="<?php echo $allXacct['id']; ?>" class="btn btn-danger btn-rounded btn-icon">
                            <i class="mdi mdi-trash-can"></i>
                      </button>
                      </form>
                    </td>
                        </tr>
          <?php } ?>
                      </tbody>
                    </table>
                  </div>
                  <div class="col-12 d-flex justify-content-center py-3">
                         <button class="btn btn-sm btn-primary" type="button" data-toggle="modal" data-target="#transaction_code" name="" value="submit">Add Transaction Codes</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          
          <div class="row">
            <div class="col-lg-12 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <h4 class="card-title">Tansaction History</h4>
                  <div class="table-responsive">
                    <table class="table">
                      <thead>
                        <tr>
                          <!--<th>Type</th>-->
                          <th>Description</th>
                          <th>Amount</th>
                          <th>Transfer Status</th>
                          <th>Balance</th>
                          <th>Date Registered</th>
                          <th>Action</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
          $allacct = $bankdata->get_transactionX(adminurl);
          
          foreach($allacct as $allXacct){
              $elsedata = ($allXacct['bn_bank'] == 'Celtic Capital' && $allXacct['trans_from'] == adminurl)?$allXacct['other_balance']:$allXacct['acct_balance'];
			   $trn_notes = ($allXacct['bn_bank'] == 'Celtic Capital' && $allXacct['trans_from'] == adminurl)?$allXacct['tran_notes_2']:$allXacct['trans_notes'];
                        ?><tr>
                          <!--<td><?php echo $allXacct['payment_type']; ?></td>-->
                        <td><?php echo $trn_notes; ?> 
                        <!--<br>-->
                        <?php //echo $allXacct['reciever_data']; ?>
                        </td>
                          <td><?php echo $singleClient['active_currency'].number_format($allXacct['trans_amount'],2); ?></a>
                        </td>
                          <td>    
                          <form action="/admin/view_client/<?php echo adminurl; ?>" method="post">
                      <div class="form-group">
                    <div class="input-group">
                    <?php
                    $disabled = '';
                      if('success' == $allXacct['trans_status']){
                        $disabled = '';
                      }
                      ?>
                    <input type="hidden" name="trnsamt" value="<?php echo $allXacct['trans_amount']; ?>">
                    <input type="hidden" name="transaction_id" value="<?php echo $allXacct['transaction_id']; ?>">
                    <select class="form-control" <?php echo $disabled; ?> name="transfer_stat_val">
                      <?php
                      if($stats == $allXacct['trans_status']){}
                      foreach(['success','pending','failed'] as $stats){
                          if($stats == $allXacct['trans_status']){
                            echo '<option value="'.$stats.'" selected> '.$stats.'</option>';
                          }else{
                            echo '<option value="'.$stats.'"> '.$stats.'</option>';
                          }
                      }
                      ?>
                    </select>
                      <div class="input-group-append">
                        <button class="btn btn-sm btn-primary" type="submit" name="" value="submit" <?php echo $disabled; ?>>Update</button>
                      </div>
                      
                    </div>
                  </div>
                  </form>
                          
                        </td>
                        <td><?php echo $singleClient['active_currency'].number_format($elsedata,2); ?>
                        </td>
                          <td>
                            <form action="/admin/view_client/<?php echo adminurl; ?>" method="post">
                      <div class="form-group">
                    <div class="input-group">
                        <input type="hidden" name="transaction_id" value="<?php echo $allXacct['transaction_id']; ?>">
                    <input type="datetime-local" name="newdate" value="<?php echo $allXacct['created_at']; ?>">
                      <div class="input-group-append">
                        <button class="btn btn-sm btn-primary" type="submit" name="" value="submit">Update</button>
                      </div>
                      
                    </div>
                  </div>
                  </form>  
                    </td><td>
                        <form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
                            <input type="hidden" name="amount" value="<?php echo $allXacct['trans_amount']; ?>">
                            <input type="hidden" name="type" value="<?php echo $allXacct['payment_type']; ?>">
                            <input type="hidden" name="acctnum" value="<?php echo adminurl; ?>">
                        <button type="submit" name="delete_transaction" value="<?php echo $allXacct['transaction_id']; ?>" class="btn btn-danger btn-rounded btn-icon">
                            <i class="mdi mdi-trash-can"></i>
                      </button>
                      </form>
                        </td>
                        </tr>
          <?php } ?>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>
          
          
          
</div>


<!-- Modal -->
<div class="modal fade" id="transaction_code" tabindex="-1" role="dialog" aria-labelledby="transaction_codeTitle" aria-hidden="true" data-backdrop="true">
  <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
    <div class="modal-content rounded-0 border-0">
      <div class="modal-body">
      <div class="col-12 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">			
                  <h3 class="card-title">Add New Transaction Code</h3>
                  <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST" enctype="multipart/form-data">
                    <div class="form-group">
                      <label for="acct_name">Code Name:</label>
                      <input type="text" class="form-control" id="name" name="name" placeholder="Code Name" required>
                    </div>
                    <div class="form-group">
                      <label for="acct_phone">Code</label>
                      <input type="text" class="form-control" id="codes" name="codes" placeholder="Enter Code" required>
                    </div>
                    <div class="form-group">
                      <label for="acct_email">Instructions</label>
                        <textarea class="form-control" id="instruction" name="instruction" placeholder="Enter Instructions" required></textarea>
                    </div>
                    <button type="submit" name="create_code" class="btn btn-primary mr-2">Create Code</button>
                  </form>
                </div>
              </div>
            </div>
      </div>
    </div>
  </div>
</div>
<script>
function generateRandomNumber() {
  const min = Math.pow(10, 9); // Minimum 10-digit number
  const max = Math.pow(10, 10) - 1; // Maximum 10-digit number
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
function numberFormat(value, decimalPlaces = 2, locale = 'en-US') {
      return Number(value).toLocaleString(locale, {
        minimumFractionDigits: decimalPlaces,
        maximumFractionDigits: decimalPlaces,
      });
    }
    const firstNames = [
  'Emma', 'Liam', 'Olivia', 'Noah', 'Ava', 'Isabella', 'Sophia', 'Jackson', 'Lucas', 'Aiden',
  'Mia', 'Ethan', 'Alexander', 'Avery', 'Evelyn', 'Abigail', 'Harper', 'Ella', 'Grace', 'Nora',
  'Scarlett', 'Riley', 'Chloe', 'Leo', 'Lily', 'Mason', 'Ellie', 'Zoe', 'Sofia', 'Luna',
  'Aria', 'Benjamin', 'Carter', 'Mila', 'Layla', 'Henry', 'Sebastian', 'Aaliyah', 'Gabriel', 'Zachary',
  'Sadie', 'Nathan', 'Eli', 'Levi', 'Peyton', 'Brooklyn', 'Samuel', 'Hannah', 'Christopher', 'Isaac'
];
const surnames = [
  'Smith', 'Johnson', 'Williams', 'Jones', 'Brown', 'Davis', 'Miller', 'Wilson', 'Moore', 'Taylor',
  'Anderson', 'Thomas', 'Jackson', 'White', 'Harris', 'Martin', 'Thompson', 'Garcia', 'Martinez', 'Robinson',
  'Clark', 'Rodriguez', 'Lewis', 'Lee', 'Walker', 'Hall', 'Allen', 'Young', 'Hernandez', 'King',
  'Wright', 'Lopez', 'Hill', 'Scott', 'Green', 'Adams', 'Baker', 'Gonzalez', 'Nelson', 'Carter',
  'Mitchell', 'Perez', 'Roberts', 'Turner', 'Phillips', 'Campbell', 'Parker', 'Evans', 'Edwards', 'Collins'
];


    // Function to generate a random name
    function generateRandomName(data) {
        let RanAccNum = generateRandomNumber();
      // Get random name and surname
      const randomName = firstNames[Math.floor(Math.random() * firstNames.length)];
      const randomSurname = surnames[Math.floor(Math.random() * surnames.length)];

      // Set the generated name into the input field
      const fullNameInput = document.getElementById('trans_desc_'+data);
      let Amount = document.getElementById(data+'_amount').value;
      let selected_cur = document.getElementById('selected_currency').innerText;
            Amount = Amount === "" ? 0 : selected_cur+numberFormat(Amount);
        let ucase = data === "debit" ? 'to' : 'from';

    //   console.log(fullNameInput.innerText);
    document.querySelector('#'+data+'_bn_name').value = `${randomName} ${randomSurname}`;
    document.querySelector('#'+data+'_bn_accno').value = `${RanAccNum}`;
      fullNameInput.innerText = `${data} of ${Amount} ${ucase}  ${randomName} ${randomSurname}, ${RanAccNum}`;
    }

</script>