HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/unbox/uc-live/admin-dash/invoice-data.php
<?php
include_once('../wp-config.php');
global $wpdb;
global $current_user;
wp_get_current_user();
$user_id = $current_user->ID;

session_start();
if ($_SESSION['date-filter']) {
	$subquery = $_SESSION["date-filter"];
} else {
	$subquery = " AND MONTH(transaction_date) = MONTH(now()) AND YEAR(transaction_date) = YEAR(now())";
}

/// get current finacial details
if (date('m') < 4) { //Upto April
	$currentYear = date('Y');
} else { //After April 
	$currentYear = (date('Y') + 1);
}

if ($_SESSION['fy-filter']) {
	$year_filter = $_SESSION["fy-filter"];
	$years = (explode("_", $year_filter));
	$last_year = $years[0];
	$present_year = $years[1];
	if ($present_year == $currentYear) {
		$subTable = "unbox_invoice";
	} else {
		$subTable = 'unbox_invoice_' . $year_filter;
	}
} else {
	$subTable = "unbox_invoice";
}

$requestData = $_REQUEST;
$columns = array(
	0 => 'invoice_id',
	1 => 'view',
	2 => 'domain',
	3 => 'vendor',
	4 => 'txn_type',
	5 => 'payment_for',
	6 => 'order_id',
	7 => 'product_mrp',
	8 => 'c_name',
	9 => 'c_mobile',
	10 => 'txn_date'
);

$getDataQuery = "SELECT count(invoice_id) from $subTable as i WHERE invoice_id !='' $subquery";

$getData = $wpdb->get_var($getDataQuery);
$totalData = $getData;
$totalFiltered = $getData;

$searchTerms = "";
if (!empty($requestData['search']['value'])) {
	$searchTerms .= " AND ( customer_name LIKE '" . $requestData['search']['value'] . "%' ";
	$searchTerms .= " OR customer_mobile LIKE '" . $requestData['search']['value'] . "%' ";
	$searchTerms .= " OR customer_email LIKE '" . $requestData['search']['value'] . "%') ";
}

$getUsersQuery = "SELECT invoice_id, from_domain, if_vendor, transaction_type, payment_for, payment_type, order_id, product_mrp, gst_rate, igst_amount, cgst_amount, sgst_amount, taxable_amount, unbox_amount, discount_amount, net_amount, customer_name, customer_address, customer_mobile, customer_email, customer_gst_name, customer_gstin, customer_state_id, customer_state_code, customer_state_name, transaction_id1, transaction_id2, transaction_date, invoice_issue_date, year_extn, invoice_status, cancelled_reason_if_any, system_datetime, cancelled_datetime, ref_name1, ref_id1, ref_name2, ref_id2, ref_name3, ref_id3, last_update_date, source from $subTable where invoice_id !='' $subquery $searchTerms";

$getUsersQuery .= " ORDER BY " . $columns[$requestData['order'][0]['column']] . " " . $requestData['order'][0]['dir'] . "  LIMIT " . $requestData['start'] . ", " . $requestData['length'] . "   ";
// echo $getUsersQuery;

$getData = $wpdb->get_results($getUsersQuery);

$data = array();
foreach ($getData as $invc) {
	$edit = '';
	if ($invc->invoice_status == 0) {
		$view = '<span style="font-size:15px; color:#ff0000;">Cancelled</span>';
	} else {
		$view = '<a title="Success" href="txn_receipt.php?id=' . $invc->invoice_id . '" target="_blank">Receipt</a> | 
		<span style="font-size:15px; color:#007bff; cursor:pointer;" title="View Detail" data-bs-toggle="modal" data-bs-target="#detailModal" onclick="viewData(' . $invc->invoice_id . ')">Detail</span>';
	}

	if ($invc->source == 'M' && $invc->source != '' && $invc->invoice_status == '2') {
		$edit = ' | <a title="Success" href="edit-invoice.php?id=' . $invc->invoice_id . '" target="_blank">Edit</a>';
	}

	// inv_id viewr view domain vendor txn_type payment_for order_id product_mrp, c_name, c_mobile, txn_date
	$nestedData = array();
	$nestedData["invoice_id"] = $invc->invoice_id;
	$nestedData["view"] = $view . $edit;
	$nestedData["domain"] = $invc->from_domain;
	$nestedData["vendor"] = $invc->if_vendor;
	$nestedData["txn_type"] = $invc->transaction_type;
	$nestedData["payment_for"] = $invc->payment_for;
	$nestedData["order_id"] = $invc->order_id;
	$nestedData["product_mrp"] = $invc->product_mrp;
	$nestedData["c_name"] = $invc->customer_name;
	$nestedData["c_mobile"] = $invc->customer_mobile;
	$nestedData["txn_date"] = $invc->transaction_date;

	$data[] = $nestedData;
}

$json_data = array(
	"draw"            => intval($requestData['draw']),
	"recordsTotal"    => intval($totalData),
	"recordsFiltered" => intval($totalFiltered),
	"data"            => $data
);

echo json_encode($json_data);