<?php
/**
 *
 * @ WHMCS FULL DECODED & NULLED
 *
 * @ Version  : 5.2.15
 * @ Author   : MTIMER
 * @ Release on : 2013-12-24
 * @ Website  : http://www.mtimer.cn
 *
 **/

if (!defined("WHMCS")) {
	exit("This file cannot be accessed directly");
}


if (!$limitstart) {
	$limitstart = 0;
}


if (!$limitnum) {
	$limitnum = 25;
}

$where = array();

if ($userid) {
	$where[] = "tblinvoices.userid='" . (int)$userid . "'";
}


if ($status) {
	if ($status == "Overdue") {
		$where[] = "tblinvoices.status='Unpaid' AND tblinvoices.duedate<'" . date("Ymd") . "'";
	}
	else {
		$where[] = "tblinvoices.status='" . db_escape_string($status) . "'";
	}
}

$where = implode(" AND ", $where);

$result = full_query("SELECT * FROM tblinvoiceitems");

$sum = select_query("tblinvoices", "SUM(subtotal)", array("userid" => $userid));
$sumtotal = mysql_fetch_array($sum);
$amount = $sumtotal[0];

$apiresults = array("result" => "success", "totalresults" => $amount, "startnumber" => $limitstart, "numreturned" => mysql_num_rows($result), "invoicesitems" => array());

while ($data = mysql_fetch_assoc($result)) {
	$currency = getCurrency($userid);
	$data['currencycode'] = $currency['code'];
	$data['currencyprefix'] = $currency['prefix'];
	$data['currencysuffix'] = $currency['suffix'];
	$apiresults['invoicesitems']['invoicesitem'][] = $data;
}

$responsetype = "xml";
?>