File: /var/www/selfanalyse/accounts-admin/invoice_data_excel.php
<?php
include("../wp-config.php");
global $wpdb;
$PSY_INVOICE = $wpdb->prefix . PSY_INVOICE;
$PSY_PLANS = $wpdb->prefix . PSY_PLANS;
if (!empty($_SESSION['Inv_subQuery'])) {
$mergeFilter = $_SESSION['Inv_subQuery'];
} else {
$mergeFilter = "";
}
$csv_output = 'S.no,Invoice Id,Type,Plan,Amount,Transaction id,Name,Email,State,Gstin,Year Extn,Txn Date,Issue Date';
$csv_output .= "\n";
$getInvoice = $wpdb->get_results("SELECT id,type_extn,type,type_id,order_amount,transaction_id,name,email,address,state_id,gstin,year_extn,txn_date,issue_date FROM $PSY_INVOICE where invoice_status='1' and type_extn!='WP' $mergeFilter order by id desc");
if( sizeof($getInvoice) != 0)
{
$i = 1;
foreach ($getInvoice as $vd)
{
if($vd->type_extn == 'P' || $vd->type_extn == 'WP') {
$planName = $wpdb->get_var("SELECT plan_name FROM $PSY_PLANS where plan_id='$vd->type_id'");
} else {
$planName = 'Counselor';
}
$s = $vd->date_of_birth;
$dt = new DateTime($s);
$date = $dt->format('d-m-Y');
$srno=$i+$indexN;
$csv_output .= $i . ',';
$csv_output .= 'SA'.$vd->id . ',';
$csv_output .= $vd->type . ',';
$csv_output .= $planName . ',';
$csv_output .= $vd->order_amount . ',';
$csv_output .= $vd->transaction_id . ',';
$csv_output .= $vd->name . ',';
$csv_output .= $vd->email . ',';
$csv_output .= $vd->state_id . ',';
$csv_output .= $vd->gstin . ',';
$csv_output .= $vd->year_extn . ',';
$csv_output .= $vd->txn_date . ',';
$csv_output .= $vd->issue_date . ',';
$csv_output .= "\n";
$contents = strip_tags($csv_output);
$i++;
}
} else {
$csv_output = "No Record Found!";
}
$filename = 'Selfanalyse-Invoice';
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: filename=" . $filename . ".csv");
print chr(255) . chr(254) . mb_convert_encoding($csv_output, 'UTF-16LE', 'UTF-8');
// print $csv_output;
exit;
?>