<?php
function sm_show_account_details(){
	$html = "";
    global $wpdb;
    $wpdb_prefix = $wpdb->prefix;
    $account= $wpdb_prefix.'sm_accounts_management';

	wp_enqueue_style( 'cip-css' );
	wp_enqueue_style( 'bs-table' );
	wp_enqueue_style( 'bs-sticky-header' );
	wp_enqueue_style( 'bs-datepicker' );
	wp_enqueue_script('bs-table');
	wp_enqueue_script('bs-sticky-header');
	wp_enqueue_script('bs-table-filter-control');
	wp_enqueue_script('tbl-ex-js');
	wp_enqueue_script('jspdf');
	wp_enqueue_script('pdf-autotable-js');
	wp_enqueue_script('ex-js');
	wp_enqueue_script('bs-datepicker');
	ob_start();
	

    if( (isset( $_GET['fromdate'] ) && isset( $_GET['todate'] )) && (!empty( $_GET['fromdate'] ) && !empty( $_GET['todate'] )) ){
        $account_record = ("SELECT * FROM $account WHERE ( STR_TO_DATE(Date,'%d-%m-%y') >= STR_TO_DATE('" . $_GET['fromdate'] . "', '%d-%m-%y') AND STR_TO_DATE(Date,'%d-%m-%y') <= STR_TO_DATE('" . $_GET['todate'] . "', '%d-%m-%y') )");
    }else{
        $account_record = "SELECT * FROM $account";
    }
    $account_result = $wpdb->get_results($account_record);
            ?>

		   <div class="scroll">
			<!-- <div class="table-responsive">
				<div id="toolbar" class="select activitySelect">
				  <select class="form-control">
					<option value=""><?php _e('Export View','investor_details'); ?></option>
					<option value="all"><?php _e('Export All','investor_details'); ?></option>
				  </select>
				</div> -->
<!-- 			 <form>
		<div class="filter_area">
			<div class="input-daterange input-group" id="datepicker">
		    <input type="text" class="input-sm form-control" name="fromdate" value="<?php echo $_GET['fromdate'] ?>" placeholder="From Date"/>
		    
		    <input type="text" class="input-sm form-control" placeholder="To Date" name="todate" value="<?php echo $_GET['todate'] ?>" />
			</div>
		</div>
		<button type="submit"><?php _e('Filter',CIP_TXTDOMAIN); ?></button>
		<a href="<?php echo get_the_permalink(); ?>"><?php _e('Clear',CIP_TXTDOMAIN); ?></a>
	</form> -->
            <table id="tokenholder_table"
		  data-filter-control="true"
		  data-show-search-clear-button="false" data-pagination="true" data-sortable="true" data-toggle="table" data-show-columns="true" data-show-columns-toggle-all="true" data-show-toggle="false" data-show-export="true" data-export-types="['csv', 'pdf']"  class="table table-bordered">
          <thead>
				<tr>
                <th data-field="id" data-filter-control="input" data-sortable="true" class="id" data-switchable="false" data-width="50" data-width-unit="px"><?php _e('#', CIP_TXTDOMAIN); ?></th>
					<th data-field="status" data-filter-control="select" data-filter-custom-search="BsTableFilterStatus" data-sortable="true" class="status"><?php _e('Status', CIP_TXTDOMAIN); ?></th>
					<th data-field="assign" data-filter-control="input" data-sortable="true" class="assign"><?php _e('Assigned To', CIP_TXTDOMAIN); ?></th>
					<th data-field="holder" data-filter-control="input" data-sortable="true" class="holder"><?php _e('Account Holder', CIP_TXTDOMAIN); ?></th>
					<th data-field="iban" data-filter-control="input" data-visible="false" data-sortable="true" class="iban"><?php _e('IBAN', CIP_TXTDOMAIN); ?></th>
                    <th data-field="bic" data-filter-control="input" data-visible="false" data-sortable="true" class="bic"><?php _e('BIC', CIP_TXTDOMAIN); ?></th>
					<th data-field="BankCode" data-filter-control="input" data-sortable="true" class="BankCode"><?php _e('Bank Code', CIP_TXTDOMAIN); ?></th>
                    <th data-field="BankName" data-filter-control="input" data-sortable="true" class="BankName"><?php _e('Bank Name', CIP_TXTDOMAIN); ?></th>
                    <th data-field="BankAddress" data-filter-control="input" data-visible="false" data-sortable="true" class="BankAddress"><?php _e('Bank Address', CIP_TXTDOMAIN); ?></th>
                    <th data-field="Date" data-filter-control="input" data-sortable="true" class="Date"><?php _e('Date', CIP_TXTDOMAIN); ?></th>																					<th data-switchable="false"></th>										
				</tr>
					</thead>
            <?php
			$sno=1;
            foreach($account_result as $row){
				$id = $row->id;
            ?>	
                 <tr>
                    <td>
                        <?php echo $id; ?>
                    </td> 
					 
					<td>
                        <?php echo $row->Status; ?>
                    </td>

					<td>
                        <?php echo $row->AssignedTo; ?>
                    </td>

					<td>
                        <?php echo $row->AccountHolder; ?>
                    </td>
					
					 <td>
                        <?php echo $row->IBAN; ?>
                    </td>

                    <td>
                        <?php echo $row->BIC; ?>
                    </td>
					
                    <td>
                        <?php echo $row->BankCode; ?>
                    </td>
					
                   <td>
                        <?php  echo $row->BankName; ?>
                    </td>

                    <td>
                        <?php  echo $row->BankAddress; ?>
                    </td>

                    <td>
                        <?php  echo $row->Date; ?>
                    </td>

                 <td>
					<?php 
						$path = get_permalink( get_page_by_title( 'SM Update Accounts Details' ) );
						$site =get_permalink( get_page_by_title( 'SM View Accounts' ) );
				        $view =get_permalink( get_page_by_title( 'SM View Single Account Details' ) );
					 ?>
					 
					 <a href="<?php echo $view;?>?id=<?php echo $id; ?>" title="View Account Details" class="ml-2"  style="color:#000;text-decoration:none;"><i class="fas fa-eye"></i></a>
					 
<a class="ml-2" title="Update Account Details" href="<?php echo $path; ?>?id=<?php echo $id; ?>" style="color:#000;text-decoration:none;">
                    <i class="fa fa-edit"></i></a>
					 
                    </td>
					
                </tr> 	
            	
        <?php $sno=$sno+1;} ?>
			
            </table><br>
			  </div>  			      

        <?php 
		// DELETE ACCOUNT DETAILS
		if(isset($_GET['id'])){
			$idd = $_GET['id'];
			$wpdb->delete( $account, array( 'id' => $idd ) );
			$curr_page = get_the_permalink();
			?>
			<script>
				window.location.href = `<?php echo $curr_page;?> `;
			</script>
		<?php
		}
		// END CODE
}

?>
<script>
    jQuery(document).ready(function(){
		if( jQuery('#tokenholder_table').length > 0 ){			
			var $tableTH = jQuery('#tokenholder_table');
			$tableTH.bootstrapTable();
			jQuery('#toolbar').find('select').change(function () {
				$tableTH.bootstrapTable('destroy').bootstrapTable({
				  exportDataType: jQuery(this).val(),
				  exportTypes: ['csv', 'pdf'],
				});
			});
		}
		jQuery('.filter_area .input-daterange').datepicker({
            format: 'dd-mm-yyyy',
            autoclose: true,
        });
    });
</script>