mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #9181 from turbo124/v5-develop
Add Net / tax amounts to expense reports
This commit is contained in:
commit
3efa1bac78
@ -387,6 +387,8 @@ class BaseExport
|
|||||||
|
|
||||||
protected array $expense_report_keys = [
|
protected array $expense_report_keys = [
|
||||||
'amount' => 'expense.amount',
|
'amount' => 'expense.amount',
|
||||||
|
'tax_amount' => 'expense.tax_amount',
|
||||||
|
'net_amount' => 'expense.net_amount',
|
||||||
'category' => 'expense.category_id',
|
'category' => 'expense.category_id',
|
||||||
// 'client' => 'expense.client_id',
|
// 'client' => 'expense.client_id',
|
||||||
'custom_value1' => 'expense.custom_value1',
|
'custom_value1' => 'expense.custom_value1',
|
||||||
|
@ -23,6 +23,7 @@ use League\Csv\Writer;
|
|||||||
|
|
||||||
class ExpenseExport extends BaseExport
|
class ExpenseExport extends BaseExport
|
||||||
{
|
{
|
||||||
|
|
||||||
private $expense_transformer;
|
private $expense_transformer;
|
||||||
|
|
||||||
private Decorator $decorator;
|
private Decorator $decorator;
|
||||||
@ -72,6 +73,13 @@ class ExpenseExport extends BaseExport
|
|||||||
$this->input['report_keys'] = array_values($this->expense_report_keys);
|
$this->input['report_keys'] = array_values($this->expense_report_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$tax_keys = [
|
||||||
|
'expense.tax_amount',
|
||||||
|
'expense.net_amount'
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->input['report_keys'] = array_merge($this->input['report_keys'], $tax_keys);
|
||||||
|
|
||||||
$query = Expense::query()
|
$query = Expense::query()
|
||||||
->with('client')
|
->with('client')
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
@ -117,15 +125,11 @@ class ExpenseExport extends BaseExport
|
|||||||
} elseif (array_key_exists($key, $transformed_expense)) {
|
} elseif (array_key_exists($key, $transformed_expense)) {
|
||||||
$entity[$key] = $transformed_expense[$key];
|
$entity[$key] = $transformed_expense[$key];
|
||||||
} else {
|
} else {
|
||||||
// nlog($key);
|
|
||||||
$entity[$key] = $this->decorator->transform($key, $expense);
|
$entity[$key] = $this->decorator->transform($key, $expense);
|
||||||
// $entity[$key] = '';
|
|
||||||
// $entity[$key] = $this->resolveKey($key, $expense, $this->expense_transformer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return $entity;
|
|
||||||
return $this->decorateAdvancedFields($expense, $entity);
|
return $this->decorateAdvancedFields($expense, $entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +175,38 @@ class ExpenseExport extends BaseExport
|
|||||||
$entity['expense.category_id'] = $expense->category ? $expense->category->name : '';
|
$entity['expense.category_id'] = $expense->category ? $expense->category->name : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->calcTaxes($entity, $expense);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calcTaxes($entity, $expense): array
|
||||||
|
{
|
||||||
|
$precision = $expense->currency->precision ?? 2;
|
||||||
|
|
||||||
|
$entity['expense.net_amount'] = round($expense->amount, $precision);
|
||||||
|
|
||||||
|
if($expense->calculate_tax_by_amount) {
|
||||||
|
$total_tax_amount = round($expense->tax_amount1 + $expense->tax_amount2 + $expense->tax_amount3, $precision);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
if($expense->uses_inclusive_taxes){
|
||||||
|
$total_tax_amount = ($this->calcInclusiveLineTax($expense->tax_rate1 ?? 0, $expense->amount,$precision)) + ($this->calcInclusiveLineTax($expense->tax_rate2 ?? 0, $expense->amount,$precision)) + ($this->calcInclusiveLineTax($expense->tax_rate3 ?? 0, $expense->amount,$precision));
|
||||||
|
$entity['expense.net_amount'] = round(($expense->amount - round($total_tax_amount, $precision)), $precision);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$total_tax_amount = ($expense->amount * (($expense->tax_rate1 ?? 0)/100)) + ($expense->amount * (($expense->tax_rate2 ?? 0)/100)) + ($expense->amount * (($expense->tax_rate3 ?? 0)/100));
|
||||||
|
$entity['expense.net_amount'] = round(($expense->amount + round($total_tax_amount, $precision)), $precision);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$entity['expense.tax_amount'] = round($total_tax_amount, $precision);
|
||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calcInclusiveLineTax($tax_rate, $amount, $precision): float
|
||||||
|
{
|
||||||
|
return round($amount - ($amount / (1 + ($tax_rate / 100))), $precision);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class SearchController extends Controller
|
|||||||
->when(!$user->hasPermission('view_all') || !$user->hasPermission('view_client'), function ($query) use ($user) {
|
->when(!$user->hasPermission('view_all') || !$user->hasPermission('view_client'), function ($query) use ($user) {
|
||||||
$query->where('user_id', $user->id);
|
$query->where('user_id', $user->id);
|
||||||
})
|
})
|
||||||
->orderBy('id', 'desc')
|
->orderBy('updated_at', 'desc')
|
||||||
->take(1000)
|
->take(1000)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
@ -741,6 +741,10 @@ class HtmlEngine
|
|||||||
|
|
||||||
if((int)$this->client->country_id !== (int)$this->company->settings->country_id) {
|
if((int)$this->client->country_id !== (int)$this->company->settings->country_id) {
|
||||||
$tax_label .= ctrans('texts.intracommunity_tax_info') . "<br>";
|
$tax_label .= ctrans('texts.intracommunity_tax_info') . "<br>";
|
||||||
|
|
||||||
|
if($this->entity_calc->getTotalTaxes() > 0)
|
||||||
|
$tax_label = '';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tax_label;
|
return $tax_label;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user