芝麻web文件管理V1.00
HTML;
}
$currency = getCurrency($userid);
$statement = array();
$count = $balance = $totalcredits = $totaldebits = 0;
if ($userid) {
$results = Capsule::table('tblinvoices')
->where('userid', '=', $userid)
->whereIn(
'status',
[
'Unpaid',
'Paid',
'Collections',
]
)
->orderBy('date', 'asc')
->get()
->all();
foreach ($results as $result) {
$invoiceid = $result->id;
$date = $result->date;
$total = ($result->credit + $result->total);
$addfunds = Capsule::table('tblinvoiceitems')
->where('invoiceid', '=', $invoiceid)
->whereIn(
'type',
[
'AddFunds',
'Invoice',
]
)
->value('id');
if (!$addfunds) {
$statement[str_replace('-', '', $date) . "_" . $count] = [
'type' => 'Invoice',
'date' => Carbon::safeCreateFromMySqlDate($date),
'description' => "
#{$invoiceid}",
'credits' => 0,
'debits' => $total,
];
}
$count++;
}
$results = Capsule::table('tblaccounts')
->where('userid', '=', $userid)
->orderBy('date', 'asc')
->get()
->all();
foreach ($results as $result) {
$transid = $result->id;
$date = $result->date;
$description = $result->description;
$amountin = $result->amountin;
$amountout = $result->amountout;
$invoiceid = $result->invoiceid;
$date = substr($date, 0, 10);
$itemtype = Capsule::table('tblinvoiceitems')
->where('invoiceid', '=', $invoiceid)
->value('type');
if ($itemtype == "AddFunds") {
$description = "Credit Prefunding";
} elseif ($itemtype == "Invoice") {
$description = "Mass Invoice Payment - ";
$relids = Capsule::table('tblinvoiceitems')
->where('invoiceid', '=', $invoiceid)
->orderBy('relid', 'asc')
->pluck('relid')
->all();
foreach ($relids as $relid) {
$description .= "
#{$relid}, ";
}
$description = substr($description, 0, -2);
} else {
if ($invoiceid) {
$description .= " -
"
. "#$invoiceid";
}
}
$statement[str_replace('-', '', $date) . "_" . $count] = [
'type' => 'Transaction',
'date' => Carbon::safeCreateFromMySqlDate($date),
'description' => $description,
'credits' => $amountin,
'debits' => $amountout,
];
$count++;
}
}
$datefrom = $dateto = '';
if ($range) {
$dateRange = Carbon::parseDateRangeValue($range);
$datefrom = $dateRange['from'];
$dateto = $dateRange['to'];
}
$reportdata['tableheadings'] = ['Type', 'Date', 'Description', 'Credits', 'Debits', 'Balance'];
ksort($statement);
$previousBalance = null;
foreach ($statement as $entry) {
/** @var Carbon $carbonDate */
$carbonDate = $entry['date'];
// only update the total balance to include previous balance through to ending date of report
if ($carbonDate->lte($dateto)) {
$balance += ($entry['credits'] - $entry['debits']);
}
if (!empty($range) && $carbonDate->lt($datefrom)) {
$previousBalance = $balance;
}
if (empty($range) || $carbonDate->betweenIncluded($datefrom, $dateto)) {
$reportdata['tablevalues'][] = [
$entry['type'],
$carbonDate->toClientDateFormat(),
$entry['description'],
formatCurrency($entry['credits']),
formatCurrency($entry['debits']),
formatCurrency($balance),
];
$totalcredits += $entry['credits'];
$totaldebits -= $entry['debits'];
}
}
if (!empty($previousBalance)) {
$previousBalance = formatCurrency($previousBalance);
} else {
$previousBalance = AdminLang::trans('global.na');
}
$previousBalanceLabel = AdminLang::trans('reports.clientStatement.previousBalance');
$reportdata['tablePreface'] = <<
{$previousBalanceLabel}: {$previousBalance}
PREFACE;
$reportdata["tablevalues"][] = array(
'#efefef',
'',
'',
'Ending Balance',
''.formatCurrency($totalcredits).'',
''.formatCurrency($totaldebits).'',
''.formatCurrency($balance).''
);