mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
Merge remote-tracking branch 'upstream/develop' into develop
This commit is contained in:
commit
5cbfbda947
@ -385,7 +385,7 @@ class ReportController extends BaseController
|
||||
$isExport ? $client->getDisplayName() : $client->present()->link,
|
||||
$isExport ? $invoice->invoice_number : $invoice->present()->link,
|
||||
$invoice->present()->invoice_date,
|
||||
$invoiceItem->qty,
|
||||
round($invoiceItem->qty, 2),
|
||||
$invoiceItem->product_key,
|
||||
];
|
||||
//$reportTotals = $this->addToTotals($reportTotals, $client->currency_id, 'paid', $payment ? $payment->amount : 0);
|
||||
@ -464,36 +464,31 @@ class ReportController extends BaseController
|
||||
*/
|
||||
private function generateExpenseReport($startDate, $endDate, $isExport)
|
||||
{
|
||||
$columns = ['vendor', 'client', 'date', 'expense_amount', 'invoiced_amount'];
|
||||
$columns = ['vendor', 'client', 'date', 'expense_amount'];
|
||||
|
||||
$account = Auth::user()->account;
|
||||
$displayData = [];
|
||||
$reportTotals = [];
|
||||
|
||||
$expenses = Expense::scope()
|
||||
->withTrashed()
|
||||
->withArchived()
|
||||
->with('client.contacts', 'vendor')
|
||||
->where('expense_date', '>=', $startDate)
|
||||
->where('expense_date', '<=', $endDate);
|
||||
|
||||
|
||||
foreach ($expenses->get() as $expense) {
|
||||
$amount = $expense->amount;
|
||||
$invoiced = $expense->present()->invoiced_amount;
|
||||
$amount = $expense->amountWithTax();
|
||||
|
||||
$displayData[] = [
|
||||
$expense->vendor ? ($isExport ? $expense->vendor->name : $expense->vendor->present()->link) : '',
|
||||
$expense->client ? ($isExport ? $expense->client->getDisplayName() : $expense->client->present()->link) : '',
|
||||
$expense->present()->expense_date,
|
||||
Utils::formatMoney($amount, $expense->currency_id),
|
||||
Utils::formatMoney($invoiced, $expense->invoice_currency_id),
|
||||
];
|
||||
|
||||
$reportTotals = $this->addToTotals($reportTotals, $expense->expense_currency_id, 'amount', $amount);
|
||||
$reportTotals = $this->addToTotals($reportTotals, $expense->invoice_currency_id, 'amount', 0);
|
||||
|
||||
$reportTotals = $this->addToTotals($reportTotals, $expense->invoice_currency_id, 'invoiced', $invoiced);
|
||||
$reportTotals = $this->addToTotals($reportTotals, $expense->expense_currency_id, 'invoiced', 0);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -1089,4 +1089,12 @@ class Utils
|
||||
|
||||
return url(NINJA_DOCS_URL . $page);
|
||||
}
|
||||
|
||||
public static function calculateTaxes($amount, $taxRate1, $taxRate2)
|
||||
{
|
||||
$tax1 = round($amount * $taxRate1 / 100, 2);
|
||||
$tax2 = round($amount * $taxRate2 / 100, 2);
|
||||
|
||||
return round($amount + $tax1 + $tax2, 2);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php namespace App\Models;
|
||||
|
||||
use Utils;
|
||||
use Laracasts\Presenter\PresentableTrait;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Events\ExpenseWasCreated;
|
||||
@ -205,6 +206,11 @@ class Expense extends EntityModel
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function amountWithTax()
|
||||
{
|
||||
return Utils::calculateTaxes($this->amount, $this->tax_rate1, $this->tax_rate2);
|
||||
}
|
||||
}
|
||||
|
||||
Expense::creating(function ($expense) {
|
||||
|
@ -56,14 +56,16 @@ class ExpenseDatatable extends EntityDatatable
|
||||
[
|
||||
'amount',
|
||||
function ($model) {
|
||||
$amount = Utils::calculateTaxes($model->amount, $model->tax_rate1, $model->tax_rate2);
|
||||
$str = Utils::formatMoney($amount, $model->expense_currency_id);
|
||||
|
||||
// show both the amount and the converted amount
|
||||
if ($model->exchange_rate != 1) {
|
||||
$converted = round($model->amount * $model->exchange_rate, 2);
|
||||
return Utils::formatMoney($model->amount, $model->expense_currency_id) . ' | ' .
|
||||
Utils::formatMoney($converted, $model->invoice_currency_id);
|
||||
} else {
|
||||
return Utils::formatMoney($model->amount, $model->expense_currency_id);
|
||||
$converted = round($amount * $model->exchange_rate, 2);
|
||||
$str .= ' | ' . Utils::formatMoney($converted, $model->invoice_currency_id);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
],
|
||||
[
|
||||
|
@ -24,12 +24,4 @@ class ExpensePresenter extends EntityPresenter
|
||||
return Utils::fromSqlDate($this->entity->expense_date);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function invoiced_amount()
|
||||
{
|
||||
return $this->entity->invoice_id ? $this->entity->convertedAmount() : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ class DashboardRepository
|
||||
->where('invoices.is_deleted', '=', false)
|
||||
->whereNotIn('payment_status_id', [PAYMENT_STATUS_VOIDED, PAYMENT_STATUS_FAILED]);
|
||||
} elseif ($entityType == ENTITY_EXPENSE) {
|
||||
$records->select(DB::raw('sum(expenses.amount) as total, count(expenses.id) as count, '.$timeframe.' as '.$groupBy));
|
||||
$records->select(DB::raw('sum(expenses.amount + (expenses.amount * expenses.tax_rate1 / 100) + (expenses.amount * expenses.tax_rate2 / 100)) as total, count(expenses.id) as count, '.$timeframe.' as '.$groupBy));
|
||||
}
|
||||
|
||||
return $records;
|
||||
@ -335,8 +335,12 @@ class DashboardRepository
|
||||
|
||||
public function expenses($accountId, $userId, $viewAll)
|
||||
{
|
||||
$amountField = DB::getQueryGrammar()->wrap('expenses.amount', true);
|
||||
$taxRate1Field = DB::getQueryGrammar()->wrap('expenses.tax_rate1', true);
|
||||
$taxRate2Field = DB::getQueryGrammar()->wrap('expenses.tax_rate2', true);
|
||||
|
||||
$select = DB::raw(
|
||||
'SUM('.DB::getQueryGrammar()->wrap('expenses.amount', true).') as value,'
|
||||
"SUM({$amountField} + ({$amountField} * {$taxRate1Field} / 100) + ({$amountField} * {$taxRate2Field} / 100)) as value,"
|
||||
.DB::getQueryGrammar()->wrap('expenses.expense_currency_id', true).' as currency_id'
|
||||
);
|
||||
$paidToDate = DB::table('accounts')
|
||||
|
@ -76,6 +76,8 @@ class ExpenseRepository extends BaseRepository
|
||||
'expenses.expense_currency_id',
|
||||
'expenses.invoice_currency_id',
|
||||
'expenses.user_id',
|
||||
'expenses.tax_rate1',
|
||||
'expenses.tax_rate2',
|
||||
'expense_categories.name as category',
|
||||
'invoices.public_id as invoice_public_id',
|
||||
'invoices.user_id as invoice_user_id',
|
||||
|
@ -23,7 +23,7 @@ class AccountGatewayPolicy extends EntityPolicy
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(User $user) {
|
||||
public static function create(User $user, $item) {
|
||||
return $user->hasPermission('admin');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class BankAccountPolicy extends EntityPolicy
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(User $user) {
|
||||
public static function create(User $user, $item) {
|
||||
return $user->hasPermission('admin');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class DocumentPolicy extends EntityPolicy
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(User $user)
|
||||
public static function create(User $user, $item)
|
||||
{
|
||||
return !empty($user);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class ExpenseCategoryPolicy extends EntityPolicy
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(User $user) {
|
||||
public static function create(User $user, $item) {
|
||||
return $user->is_admin;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ class PaymentTermPolicy extends EntityPolicy
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(User $user) {
|
||||
public static function create(User $user, $item) {
|
||||
return $user->hasPermission('admin');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ class TokenPolicy extends EntityPolicy {
|
||||
return $user->hasPermission('admin');
|
||||
}
|
||||
|
||||
public static function create(User $user) {
|
||||
public static function create(User $user, $item) {
|
||||
return $user->hasPermission('admin');
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@
|
||||
<center>
|
||||
<script language="javascript">
|
||||
var iframe = document.getElementById('invoiceIFrame');
|
||||
iframe.src = '{{ SITE_URL }}/view/'
|
||||
iframe.src = '{{ rtrim(SITE_URL ,'/') }}/view/'
|
||||
+ window.location.search.substring(1);
|
||||
</script></pre>
|
||||
<p>{{ trans('texts.iframe_url_help2') }}</p>
|
||||
|
Loading…
Reference in New Issue
Block a user