<!-- INvoice Page -->

<?php
function cip_member_invoice(){
	$html = "";
    global $wpdb;
    $wpdb_prefix = $wpdb->prefix;
    $invoice= $wpdb_prefix.'cip_member_invoice';
    $e_mail=$_SESSION['refAccount'];
    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'] )) ){
        $invoice_record = ("SELECT * FROM $invoice 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') ) WHERE Email='$e_mail' AND Status = 'Paid' ORDER BY `ProformaInvoiceNumber` DESC");
    }else{
        $invoice_record = "SELECT * FROM $invoice WHERE Email='$e_mail' AND Status = 'Paid' ORDER BY `ProformaInvoiceNumber` DESC";
    }
    $invoice_result = $wpdb->get_results($invoice_record);
            ?>

		   <div class="scroll">
			
			  <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="input" data-filter-custom-search="BsTableFilterStatus" data-sortable="true" class="status"><?php _e('Status', CIP_TXTDOMAIN); ?></th>
                 
                    <th data-field="Invoice" data-filter-control="input" data-sortable="true" class="Invoice #"><?php _e('Invoice #', CIP_TXTDOMAIN); ?></th>
                    <th data-field="Invoice Date" data-filter-control="input" data-sortable="true" class="InvoiceDate"><?php _e('Invoice Date', CIP_TXTDOMAIN); ?></th>
                    <th data-field="Price" data-filter-control="input" data-sortable="true" class="Price"><?php _e('(€) Price', CIP_TXTDOMAIN); ?></th>
                    <th data-field="VAT" data-filter-control="input" data-sortable="true" class="VAT"><?php _e('(€) VAT', CIP_TXTDOMAIN); ?></th>
                    <th data-field="VATparsantage" data-filter-control="input" data-filter-custom-search="BsTableFilterStatus" data-sortable="true" class="vat%"><?php _e('VAT %', CIP_TXTDOMAIN); ?></th>
                    <th data-field="price" data-filter-control="input" data-sortable="true" class="price"><?php _e('(€) Total', CIP_TXTDOMAIN); ?></th>									 <th data-field="frequency" data-filter-control="input" data-filter-custom-search="BsTableFilterStatus" data-sortable="true" class="frequency"><?php _e('Frequency', CIP_TXTDOMAIN); ?></th>								
                    <th data-field="kgs" data-filter-control="input" data-sortable="true" class="kgs"><?php _e('Kgs', CIP_TXTDOMAIN); ?></th>
                   						
                    <th data-switchable="false"></th>																												
				</tr>
					</thead>
            <?php
			$sno=1;
			if( $invoice_result ){ 
            foreach($invoice_result as $row){
				$id = $row->id;
            ?>	
                <tr>
                    <td>
                        <?php echo $sno;?>
                    </td> 

                    <td><?php echo $row->Status; ?>
                    </td>
                    <td><?php echo $InvoiceNumber = ( $row->InvoiceNumber ) ? 'CSR-'.$row->InvoiceNumber : ''; ?></td>

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

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

                    <td><?php echo $row->VATAmount; ?>
                    </td>
                     <td><?php echo $row->VATPercentage; ?>
                    </td>
    

                    <td><?php  echo $row->NetAmount; ?>
                    </td>
                      <td><?php  echo $row->Package; ?>
                    </td>
    <td><?php echo $row->Kgs; ?>
                    </td>

                    <td><?php $path = get_site_url(); ?>
<a class="ml-2" title="View Invoice" target="_blank" href="<?php echo $path; ?>/wp-content/plugins/cip-helper/includes/pdf/download_pdf.php/?id=<?php echo $id; ?>&paid=1" style="color:#000;text-decoration:none;">
                    <i class="fa fa-eye"></i></a>
                    </td>
                </tr> 	
            	<?php $sno=$sno+1;}
}?>
			
            </table><br>
			  </div>  			      

        <?php   
}
?>
<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'],
				});
			});
		}
    });
</script>