Working on expenses

This commit is contained in:
Hillel Coren 2016-01-23 23:36:31 +02:00
parent c55d23a071
commit 74a3dcf9d2
6 changed files with 60 additions and 12 deletions

View File

@ -48,6 +48,7 @@ class ExpenseController extends BaseController
'columns' => Utils::trans([ 'columns' => Utils::trans([
'checkbox', 'checkbox',
'vendor', 'vendor',
'client',
'expense_date', 'expense_date',
'amount', 'amount',
'public_notes', 'public_notes',

View File

@ -51,10 +51,19 @@ class ExpenseRepository extends BaseRepository
$query = DB::table('expenses') $query = DB::table('expenses')
->join('accounts', 'accounts.id', '=', 'expenses.account_id') ->join('accounts', 'accounts.id', '=', 'expenses.account_id')
->leftjoin('clients', 'clients.id', '=', 'expenses.client_id') ->leftjoin('clients', 'clients.id', '=', 'expenses.client_id')
->leftJoin('contacts', 'contacts.client_id', '=', 'clients.id')
->leftjoin('vendors', 'vendors.id', '=', 'expenses.vendor_id') ->leftjoin('vendors', 'vendors.id', '=', 'expenses.vendor_id')
->leftJoin('invoices', 'invoices.id', '=', 'expenses.invoice_id') ->leftJoin('invoices', 'invoices.id', '=', 'expenses.invoice_id')
->where('expenses.account_id', '=', $accountid) ->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.amount',
'expenses.currency_id', 'expenses.currency_id',
'expenses.deleted_at', 'expenses.deleted_at',
@ -69,10 +78,15 @@ class ExpenseRepository extends BaseRepository
'expenses.should_be_invoiced', 'expenses.should_be_invoiced',
'expenses.vendor_id', 'expenses.vendor_id',
'invoices.public_id as invoice_public_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.country_id as account_country_id',
'accounts.currency_id as account_currency_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' 'clients.country_id as client_country_id'
); );
@ -109,6 +123,10 @@ class ExpenseRepository extends BaseRepository
$expense->public_notes = trim($input['public_notes']); $expense->public_notes = trim($input['public_notes']);
$expense->should_be_invoiced = isset($input['should_be_invoiced']) || $expense->client_id ? true : false; $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; $rate = isset($input['exchange_rate']) ? Utils::parseFloat($input['exchange_rate']) : 1;
$expense->exchange_rate = round($rate, 4); $expense->exchange_rate = round($rate, 4);
$expense->amount = round(Utils::parseFloat($input['amount']), 2); $expense->amount = round(Utils::parseFloat($input['amount']), 2);

View File

@ -23,7 +23,23 @@ class TaskRepository
}) })
->where('contacts.deleted_at', '=', null) ->where('contacts.deleted_at', '=', null)
->where('clients.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) { if ($clientPublicId) {
$query->where('clients.public_id', '=', $clientPublicId); $query->where('clients.public_id', '=', $clientPublicId);

View File

@ -53,26 +53,37 @@ class ExpenseService extends BaseService
'vendor_name', 'vendor_name',
function ($model) function ($model)
{ {
if($model->vendor_public_id) { if ($model->vendor_public_id) {
return link_to("vendors/{$model->vendor_public_id}", $model->vendor_name); return link_to("vendors/{$model->vendor_public_id}", $model->vendor_name);
} else { } 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', 'expense_date',
function ($model) { function ($model) {
return Utils::fromSqlDate($model->expense_date); return link_to("expenses/{$model->public_id}/edit", Utils::fromSqlDate($model->expense_date));
} }
], ],
[ [
'amount', 'amount',
function ($model) { function ($model) {
// show both the amount and the converted amount // 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) { 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; return $str;
} }

View File

@ -1054,7 +1054,7 @@ return array(
'restore_expense' => 'Restore Expense', 'restore_expense' => 'Restore Expense',
'invoice_expense' => 'Invoice Expense', 'invoice_expense' => 'Invoice Expense',
'expense_error_multiple_clients' =>'The expenses can\'t belong to different clients', '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', 'convert_currency' => 'Convert currency',
// Payment terms // Payment terms

View File

@ -29,10 +29,12 @@
<div id="top_right_buttons" class="pull-right"> <div id="top_right_buttons" class="pull-right">
<input id="tableFilter" type="text" style="width:140px;margin-right:17px;background-color: white !important" <input id="tableFilter" type="text" style="width:140px;margin-right:17px;background-color: white !important"
class="form-control pull-left" placeholder="{{ trans('texts.filter') }}" value="{{ Input::get('filter') }}"/> class="form-control pull-left" placeholder="{{ trans('texts.filter') }}" value="{{ Input::get('filter') }}"/>
@if (Auth::user()->isPro() && $entityType == ENTITY_INVOICE) @if (Auth::user()->isPro() && $entityType == ENTITY_INVOICE)
{!! Button::normal(trans('texts.quotes'))->asLinkTo(URL::to('/quotes'))->appendIcon(Icon::create('list')) !!} {!! 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')) !!} {!! Button::normal(trans('texts.recurring'))->asLinkTo(URL::to('/recurring_invoices'))->appendIcon(Icon::create('list')) !!}
@elseif ($entityType == ENTITY_CLIENT) @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')) !!} {!! Button::normal(trans('texts.credits'))->asLinkTo(URL::to('/credits'))->appendIcon(Icon::create('list')) !!}
@endif @endif