mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on expenses
This commit is contained in:
parent
c55d23a071
commit
74a3dcf9d2
@ -48,6 +48,7 @@ class ExpenseController extends BaseController
|
||||
'columns' => Utils::trans([
|
||||
'checkbox',
|
||||
'vendor',
|
||||
'client',
|
||||
'expense_date',
|
||||
'amount',
|
||||
'public_notes',
|
||||
|
@ -51,10 +51,19 @@ class ExpenseRepository extends BaseRepository
|
||||
$query = DB::table('expenses')
|
||||
->join('accounts', 'accounts.id', '=', 'expenses.account_id')
|
||||
->leftjoin('clients', 'clients.id', '=', 'expenses.client_id')
|
||||
->leftJoin('contacts', 'contacts.client_id', '=', 'clients.id')
|
||||
->leftjoin('vendors', 'vendors.id', '=', 'expenses.vendor_id')
|
||||
->leftJoin('invoices', 'invoices.id', '=', 'expenses.invoice_id')
|
||||
->where('expenses.account_id', '=', $accountid)
|
||||
->select('expenses.account_id',
|
||||
->where('contacts.deleted_at', '=', null)
|
||||
->where('vendors.deleted_at', '=', null)
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->where(function ($query) {
|
||||
$query->where('contacts.is_primary', '=', true)
|
||||
->orWhere('contacts.is_primary', '=', null);
|
||||
})
|
||||
->select(
|
||||
'expenses.account_id',
|
||||
'expenses.amount',
|
||||
'expenses.currency_id',
|
||||
'expenses.deleted_at',
|
||||
@ -69,10 +78,15 @@ class ExpenseRepository extends BaseRepository
|
||||
'expenses.should_be_invoiced',
|
||||
'expenses.vendor_id',
|
||||
'invoices.public_id as invoice_public_id',
|
||||
'vendors.name as vendor_name',
|
||||
'vendors.public_id as vendor_public_id',
|
||||
'accounts.country_id as account_country_id',
|
||||
'accounts.currency_id as account_currency_id',
|
||||
'vendors.name as vendor_name',
|
||||
'vendors.public_id as vendor_public_id',
|
||||
'clients.name as client_name',
|
||||
'clients.public_id as client_public_id',
|
||||
'contacts.first_name',
|
||||
'contacts.email',
|
||||
'contacts.last_name',
|
||||
'clients.country_id as client_country_id'
|
||||
);
|
||||
|
||||
@ -109,6 +123,10 @@ class ExpenseRepository extends BaseRepository
|
||||
$expense->public_notes = trim($input['public_notes']);
|
||||
$expense->should_be_invoiced = isset($input['should_be_invoiced']) || $expense->client_id ? true : false;
|
||||
|
||||
if (! $expense->currency_id) {
|
||||
$expense->currency_id = \Auth::user()->account->getCurrencyId();
|
||||
}
|
||||
|
||||
$rate = isset($input['exchange_rate']) ? Utils::parseFloat($input['exchange_rate']) : 1;
|
||||
$expense->exchange_rate = round($rate, 4);
|
||||
$expense->amount = round(Utils::parseFloat($input['amount']), 2);
|
||||
|
@ -23,7 +23,23 @@ class TaskRepository
|
||||
})
|
||||
->where('contacts.deleted_at', '=', null)
|
||||
->where('clients.deleted_at', '=', null)
|
||||
->select('tasks.public_id', 'clients.name as client_name', 'clients.public_id as client_public_id', 'contacts.first_name', 'contacts.email', 'contacts.last_name', 'invoices.invoice_status_id', 'tasks.description', 'tasks.is_deleted', 'tasks.deleted_at', 'invoices.invoice_number', 'invoices.public_id as invoice_public_id', 'tasks.is_running', 'tasks.time_log', 'tasks.created_at');
|
||||
->select(
|
||||
'tasks.public_id',
|
||||
'clients.name as client_name',
|
||||
'clients.public_id as client_public_id',
|
||||
'contacts.first_name',
|
||||
'contacts.email',
|
||||
'contacts.last_name',
|
||||
'invoices.invoice_status_id',
|
||||
'tasks.description',
|
||||
'tasks.is_deleted',
|
||||
'tasks.deleted_at',
|
||||
'invoices.invoice_number',
|
||||
'invoices.public_id as invoice_public_id',
|
||||
'tasks.is_running',
|
||||
'tasks.time_log',
|
||||
'tasks.created_at'
|
||||
);
|
||||
|
||||
if ($clientPublicId) {
|
||||
$query->where('clients.public_id', '=', $clientPublicId);
|
||||
|
@ -53,26 +53,37 @@ class ExpenseService extends BaseService
|
||||
'vendor_name',
|
||||
function ($model)
|
||||
{
|
||||
if($model->vendor_public_id) {
|
||||
if ($model->vendor_public_id) {
|
||||
return link_to("vendors/{$model->vendor_public_id}", $model->vendor_name);
|
||||
} else {
|
||||
return 'No vendor' ;
|
||||
return '';
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'client_name',
|
||||
function ($model)
|
||||
{
|
||||
if ($model->client_public_id) {
|
||||
return link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model));
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'expense_date',
|
||||
function ($model) {
|
||||
return Utils::fromSqlDate($model->expense_date);
|
||||
return link_to("expenses/{$model->public_id}/edit", Utils::fromSqlDate($model->expense_date));
|
||||
}
|
||||
],
|
||||
[
|
||||
'amount',
|
||||
function ($model) {
|
||||
// show both the amount and the converted amount
|
||||
$str = Utils::formatMoney($model->amount, $model->account_currency_id, $model->account_country_id, true);
|
||||
$str = Utils::formatMoney($model->amount, $model->account_currency_id, $model->account_country_id);
|
||||
if ($model->exchange_rate != 1) {
|
||||
$str .= ' | ' . Utils::formatMoney(round($model->amount * $model->exchange_rate,2), $model->currency_id, $model->client_country_id, true);
|
||||
$str .= ' | ' . Utils::formatMoney(round($model->amount * $model->exchange_rate,2), $model->currency_id, $model->client_country_id);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
@ -1054,7 +1054,7 @@ return array(
|
||||
'restore_expense' => 'Restore Expense',
|
||||
'invoice_expense' => 'Invoice Expense',
|
||||
'expense_error_multiple_clients' =>'The expenses can\'t belong to different clients',
|
||||
'expense_error_invoiced' => 'Expense have already been invoiced',
|
||||
'expense_error_invoiced' => 'Expense has already been invoiced',
|
||||
'convert_currency' => 'Convert currency',
|
||||
|
||||
// Payment terms
|
||||
|
@ -32,6 +32,8 @@
|
||||
@if (Auth::user()->isPro() && $entityType == ENTITY_INVOICE)
|
||||
{!! Button::normal(trans('texts.quotes'))->asLinkTo(URL::to('/quotes'))->appendIcon(Icon::create('list')) !!}
|
||||
{!! Button::normal(trans('texts.recurring'))->asLinkTo(URL::to('/recurring_invoices'))->appendIcon(Icon::create('list')) !!}
|
||||
@elseif ($entityType == ENTITY_EXPENSE)
|
||||
{!! Button::normal(trans('texts.vendors'))->asLinkTo(URL::to('/vendors'))->appendIcon(Icon::create('list')) !!}
|
||||
@elseif ($entityType == ENTITY_CLIENT)
|
||||
{!! Button::normal(trans('texts.credits'))->asLinkTo(URL::to('/credits'))->appendIcon(Icon::create('list')) !!}
|
||||
@endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user