芝麻web文件管理V1.00
HTML;
}
if ($calculate) {
$dateRange = Carbon::parseDateRangeValue($range);
$queryStartDate = $dateRange['from']->toDateTimeString();
$queryEndDate = $dateRange['to']->toDateTimeString();
$result = Capsule::table('tblinvoices')
->select(
Capsule::raw('count(*) as `count`'),
Capsule::raw('sum(total) as `total`'),
Capsule::raw('sum(tblinvoices.credit) as `credit`'),
Capsule::raw('sum(tax) as `tax`'),
Capsule::raw('sum(tax2) as `tax2`')
)
->distinct()
->join('tblclients', 'tblclients.id', '=', 'tblinvoices.userid')
->leftJoin('tblinvoiceitems', function ($join) {
$join->on('tblinvoiceitems.invoiceid', '=', 'tblinvoices.id');
$join->on(function ($join) {
$join
->on('tblinvoiceitems.type', '=', Capsule::raw('"Add Funds"'))
->orOn('tblinvoiceitems.type', '=', Capsule::raw('"Invoice"'));
});
})
->whereBetween('tblinvoices.datepaid', [$queryStartDate, $queryEndDate])
->where('tblinvoices.status', '=', 'Paid')
->where('tblclients.currency', '=', $currencyID)
->whereNull('tblinvoiceitems.id')
->first();
$numinvoices = $result->count;
$total = ($result->total + $result->credit);
$tax = $result->tax;
$tax2 = $result->tax2;
if (!$total) $total="0.00";
if (!$tax) $tax="0.00";
if (!$tax2) $tax2="0.00";
$reportdata["headertext"] .= "
$numinvoices Invoices Found
Total Invoiced: ".formatCurrency($total)."
Tax Level 1 Liability: ".formatCurrency($tax)."
Tax Level 2 Liability: ".formatCurrency($tax2);
}
$reportdata["headertext"] .= "";
$reportdata["tableheadings"] = array(
$aInt->lang('fields', 'invoiceid'),
$aInt->lang('fields', 'clientname'),
$aInt->lang('fields', 'invoicedate'),
$aInt->lang('fields', 'datepaid'),
$aInt->lang('fields', 'subtotal'),
$aInt->lang('fields', 'tax'),
$aInt->lang('fields', 'credit'),
$aInt->lang('fields', 'total'),
);
$results = Capsule::table('tblinvoices')
->select('tblinvoices.*', 'tblclients.firstname', 'tblclients.lastname')
->distinct()
->join('tblclients', 'tblclients.id', '=', 'tblinvoices.userid')
->leftJoin('tblinvoiceitems', function ($join) {
$join->on('tblinvoiceitems.invoiceid', '=', 'tblinvoices.id');
$join->on(function ($join) {
$join
->on('tblinvoiceitems.type', '=', Capsule::raw('"Add Funds"'))
->orOn('tblinvoiceitems.type', '=', Capsule::raw('"Invoice"'));
});
})
->whereBetween('tblinvoices.datepaid', [$queryStartDate, $queryEndDate])
->where('tblinvoices.status', '=', 'Paid')
->where('tblclients.currency', '=', $currencyID)
->whereNull('tblinvoiceitems.id')
->orderBy('date', 'asc')
->get()
->all();
foreach ($results as $result) {
$id = $result->id;
$userid = $result->userid;
$client = "{$result->firstname} {$result->lastname}";
$date = fromMySQLDate($result->date);
$datepaid = fromMySQLDate($result->datepaid);
$currency = getCurrency($userid);
$subtotal = $result->subtotal;
$credit = $result->credit;
$tax = ($result->tax + $result->tax2);
$total = ($result->total + $credit);
$reportdata["tablevalues"][] = [
"{$id}",
"{$client}",
"{$date}",
"{$datepaid}",
format_as_currency($subtotal),
format_as_currency($tax),
format_as_currency($credit),
format_as_currency($total),
];
}
$data["footertext"]="This report excludes invoices that affect a clients credit balance "
. "since this income will be counted and reported when it is applied to invoices for products/services.";