mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 12:54:31 -04:00
Expense module
This commit is contained in:
parent
d89dc2e827
commit
d0bfe82512
@ -14,7 +14,7 @@ class ExpenseWasArchived extends Event
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($espense)
|
public function __construct($expense)
|
||||||
{
|
{
|
||||||
$this->expense = $expense;
|
$this->expense = $expense;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ use Redirect;
|
|||||||
use Cache;
|
use Cache;
|
||||||
use App\Models\Vendor;
|
use App\Models\Vendor;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Services\ExpenseService;
|
use App\Services\ExpenseService;
|
||||||
use App\Ninja\Repositories\ExpenseRepository;
|
use App\Ninja\Repositories\ExpenseRepository;
|
||||||
use App\Http\Requests\CreateExpenseRequest;
|
use App\Http\Requests\CreateExpenseRequest;
|
||||||
@ -45,13 +46,14 @@ class ExpenseController extends BaseController
|
|||||||
'title' => trans('texts.expenses'),
|
'title' => trans('texts.expenses'),
|
||||||
'sortCol' => '1',
|
'sortCol' => '1',
|
||||||
'columns' => Utils::trans([
|
'columns' => Utils::trans([
|
||||||
|
'checkbox',
|
||||||
'vendor',
|
'vendor',
|
||||||
'expense_amount',
|
'expense_amount',
|
||||||
'expense_date',
|
'expense_date',
|
||||||
'public_notes',
|
'public_notes',
|
||||||
'is_invoiced',
|
'is_invoiced',
|
||||||
'should_be_invoiced',
|
'should_be_invoiced',
|
||||||
'expense'
|
''
|
||||||
]),
|
]),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -76,6 +78,8 @@ class ExpenseController extends BaseController
|
|||||||
'title' => trans('texts.new_expense'),
|
'title' => trans('texts.new_expense'),
|
||||||
'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(),
|
'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(),
|
||||||
'vendor' => $vendor,
|
'vendor' => $vendor,
|
||||||
|
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
|
||||||
|
'clientPublicId' => null,
|
||||||
);
|
);
|
||||||
|
|
||||||
$data = array_merge($data, self::getViewModel());
|
$data = array_merge($data, self::getViewModel());
|
||||||
@ -95,7 +99,9 @@ class ExpenseController extends BaseController
|
|||||||
'url' => 'expenses/'.$publicId,
|
'url' => 'expenses/'.$publicId,
|
||||||
'title' => 'Edit Expense',
|
'title' => 'Edit Expense',
|
||||||
'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(),
|
'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(),
|
||||||
'vendorPublicId' => $expense->vendor_id);
|
'vendorPublicId' => $expense->vendor_id,
|
||||||
|
'clients' => Client::scope()->with('contacts')->orderBy('name')->get()
|
||||||
|
);
|
||||||
|
|
||||||
$data = array_merge($data, self::getViewModel());
|
$data = array_merge($data, self::getViewModel());
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ class ExpenseRepository extends BaseRepository
|
|||||||
$accountid = \Auth::user()->account_id;
|
$accountid = \Auth::user()->account_id;
|
||||||
$query = DB::table('expenses')
|
$query = DB::table('expenses')
|
||||||
->join('accounts', 'accounts.id', '=', 'expenses.account_id')
|
->join('accounts', 'accounts.id', '=', 'expenses.account_id')
|
||||||
|
->leftjoin('vendors','vendors.public_id','=', 'expenses.vendor_id')
|
||||||
->where('expenses.account_id', '=', $accountid)
|
->where('expenses.account_id', '=', $accountid)
|
||||||
->where('expenses.deleted_at', '=', null)
|
|
||||||
->select('expenses.account_id',
|
->select('expenses.account_id',
|
||||||
'expenses.amount',
|
'expenses.amount',
|
||||||
'expenses.amount_cur',
|
'expenses.amount_cur',
|
||||||
@ -45,12 +45,24 @@ class ExpenseRepository extends BaseRepository
|
|||||||
'expenses.public_id',
|
'expenses.public_id',
|
||||||
'expenses.public_notes',
|
'expenses.public_notes',
|
||||||
'expenses.should_be_invoiced',
|
'expenses.should_be_invoiced',
|
||||||
'expenses.vendor_id');
|
'expenses.vendor_id',
|
||||||
|
'vendors.name as vendor_name',
|
||||||
|
'vendors.public_id as vendor_public_id');
|
||||||
|
|
||||||
|
$showTrashed = \Session::get('show_trash:expense');
|
||||||
|
|
||||||
|
//var_dump($showTrashed);
|
||||||
|
|
||||||
|
if (!$showTrashed) {
|
||||||
|
$query->where('expenses.deleted_at', '=', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (!\Session::get('show_trash:expense')) {
|
if (!\Session::get('show_trash:expense')) {
|
||||||
$query->where('expenses.deleted_at', '=', null);
|
$query->where('expenses.deleted_at', '=', null);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if ($filter) {
|
if ($filter) {
|
||||||
$query->where(function ($query) use ($filter) {
|
$query->where(function ($query) use ($filter) {
|
||||||
$query->where('expenses.public_notes', 'like', '%'.$filter.'%');
|
$query->where('expenses.public_notes', 'like', '%'.$filter.'%');
|
||||||
@ -105,8 +117,10 @@ class ExpenseRepository extends BaseRepository
|
|||||||
// Calculate the amount cur
|
// Calculate the amount cur
|
||||||
$expense->amount_cur = ($expense->amount / 100) * $expense->exchange_rate;
|
$expense->amount_cur = ($expense->amount / 100) * $expense->exchange_rate;
|
||||||
|
|
||||||
|
|
||||||
$expense->should_be_invoiced = isset($input['should_be_invoiced']) ? true : false;
|
$expense->should_be_invoiced = isset($input['should_be_invoiced']) ? true : false;
|
||||||
|
if(isset($input['client'])) {
|
||||||
|
$expense->invoice_client_id = $input['client'];
|
||||||
|
}
|
||||||
$expense->save();
|
$expense->save();
|
||||||
|
|
||||||
return $expense;
|
return $expense;
|
||||||
|
@ -40,23 +40,15 @@ class ExpenseService extends BaseService
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
'vendor_id',
|
'vendor_name',
|
||||||
function ($model)
|
function ($model)
|
||||||
{
|
{
|
||||||
if($model->vendor_id) {
|
if($model->vendor_public_id) {
|
||||||
|
return link_to("vendors/{$model->vendor_public_id}", $model->vendor_name);
|
||||||
$vendors = DB::table('vendors')->where('public_id', '=',$model->vendor_id)->select('id', 'public_id','name')->get();
|
|
||||||
// should only be one!
|
|
||||||
$vendor = $vendors[0];
|
|
||||||
|
|
||||||
if($vendor) {
|
|
||||||
return link_to("vendors/{$vendor->public_id}", $vendor->name);
|
|
||||||
}
|
|
||||||
return 'no vendor: ' . $model->vendor_id;
|
|
||||||
} else {
|
} else {
|
||||||
return 'No vendor:' ;
|
return 'No vendor' ;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'amount',
|
'amount',
|
||||||
@ -79,7 +71,7 @@ class ExpenseService extends BaseService
|
|||||||
[
|
[
|
||||||
'is_invoiced',
|
'is_invoiced',
|
||||||
function ($model) {
|
function ($model) {
|
||||||
return $model->is_invoiced ? trans('texts.expense_is_invoiced') : trans('texts.expense_is_not_invoiced');
|
return $model->is_invoiced ? trans('texts.yes') : trans('texts.no');
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -88,25 +80,31 @@ class ExpenseService extends BaseService
|
|||||||
return $model->should_be_invoiced ? trans('texts.yes') : trans('texts.no');
|
return $model->should_be_invoiced ? trans('texts.yes') : trans('texts.no');
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
/*[
|
||||||
'public_id',
|
'public_id',
|
||||||
function($model) {
|
function($model) {
|
||||||
return link_to("expenses/{$model->public_id}", trans('texts.view_expense', ['expense' => $model->public_id]));
|
return link_to("expenses/{$model->public_id}", trans('texts.view', ['expense' => $model->public_id]));
|
||||||
}
|
}
|
||||||
]
|
]*/
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
protected function getDatatableActions($entityType)
|
protected function getDatatableActions($entityType)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
trans('texts.apply_expense'),
|
trans('texts.invoice_expense'),
|
||||||
function ($model) {
|
function ($model) {
|
||||||
return URL::to("espense/create/{$model->vendor_public_id}") . '?paymentTypeId=1';
|
return URL::to("expense/invoice/{$model->public_id}") . '?client=1';
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
trans('texts.view'),
|
||||||
|
function ($model) {
|
||||||
|
return URL::to("expenses/{$model->public_id}") ;
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
@ -89,7 +89,7 @@ return array(
|
|||||||
'files' => false, // Show the included files
|
'files' => false, // Show the included files
|
||||||
'config' => false, // Display config settings
|
'config' => false, // Display config settings
|
||||||
'auth' => false, // Display Laravel authentication status
|
'auth' => false, // Display Laravel authentication status
|
||||||
'session' => false, // Display session data in a separate tab
|
'session' => true, // Display session data in a separate tab
|
||||||
),
|
),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -18,13 +18,12 @@ class CreateExpensesTable extends Migration
|
|||||||
{
|
{
|
||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
|
||||||
$table->unsignedInteger('account_id')->index();
|
$table->unsignedInteger('account_id')->index();
|
||||||
$table->unsignedInteger('vendor_id')->nullable();
|
$table->unsignedInteger('vendor_id')->nullable();
|
||||||
$table->unsignedInteger('user_id');
|
$table->unsignedInteger('user_id');
|
||||||
|
$table->unsignedInteger('invoice_client_id')->nullable();
|
||||||
$table->softDeletes();
|
|
||||||
|
|
||||||
$table->boolean('is_deleted')->default(false);
|
$table->boolean('is_deleted')->default(false);
|
||||||
$table->decimal('amount', 13, 2);
|
$table->decimal('amount', 13, 2);
|
||||||
$table->decimal('amount_cur', 13, 2);
|
$table->decimal('amount_cur', 13, 2);
|
||||||
@ -36,9 +35,11 @@ class CreateExpensesTable extends Migration
|
|||||||
$table->boolean('is_invoiced')->default(false);
|
$table->boolean('is_invoiced')->default(false);
|
||||||
$table->boolean('should_be_invoiced')->default(true);
|
$table->boolean('should_be_invoiced')->default(true);
|
||||||
|
|
||||||
|
// Relations
|
||||||
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
||||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');;
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||||
|
|
||||||
|
// Indexes
|
||||||
$table->unsignedInteger('public_id')->index();
|
$table->unsignedInteger('public_id')->index();
|
||||||
$table->unique( array('account_id','public_id') );
|
$table->unique( array('account_id','public_id') );
|
||||||
});
|
});
|
||||||
|
@ -1047,11 +1047,15 @@ return array(
|
|||||||
'delete_expense' => 'Delete expense',
|
'delete_expense' => 'Delete expense',
|
||||||
'view_expense_num' => 'Expense # :expense',
|
'view_expense_num' => 'Expense # :expense',
|
||||||
'updated_expense' => 'Expense updated',
|
'updated_expense' => 'Expense updated',
|
||||||
|
'enter_expense' => 'Enter expense',
|
||||||
|
'view' => 'View',
|
||||||
|
'restore_expense' => 'Restore expense',
|
||||||
|
'invoice_expense' => 'Invoice',
|
||||||
// Payment terms
|
// Payment terms
|
||||||
'num_days' => 'Number of days',
|
'num_days' => 'Number of days',
|
||||||
'create_payment_term' => 'Create payment term',
|
'create_payment_term' => 'Create payment term',
|
||||||
'edit_payment_terms' => 'Edit payment term',
|
'edit_payment_terms' => 'Edit payment term',
|
||||||
'edit_payment_term' => 'Edit payment term',
|
'edit_payment_term' => 'Edit payment term',
|
||||||
'archive_payment_term' => 'Archive payment term',
|
'archive_payment_term' => 'Archive payment term',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
@ -33,13 +33,14 @@
|
|||||||
{!! Former::textarea('private_notes') !!}
|
{!! Former::textarea('private_notes') !!}
|
||||||
{!! Former::textarea('public_notes') !!}
|
{!! Former::textarea('public_notes') !!}
|
||||||
{!! Former::checkbox('should_be_invoiced') !!}
|
{!! Former::checkbox('should_be_invoiced') !!}
|
||||||
|
{!! Former::select('client')->addOption('', '')->addGroupClass('client-select') !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<center class="buttons">
|
<center class="buttons">
|
||||||
{!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(URL::to('/credits'))->appendIcon(Icon::create('remove-circle')) !!}
|
{!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(URL::to('/dashboard'))->appendIcon(Icon::create('remove-circle')) !!}
|
||||||
{!! Button::success(trans('texts.save'))->submit()->large()->appendIcon(Icon::create('floppy-disk')) !!}
|
{!! Button::success(trans('texts.save'))->submit()->large()->appendIcon(Icon::create('floppy-disk')) !!}
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
@ -49,6 +50,7 @@
|
|||||||
|
|
||||||
|
|
||||||
var vendors = {!! $vendors !!};
|
var vendors = {!! $vendors !!};
|
||||||
|
var clients = {!! $clients !!};
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
@ -76,7 +78,20 @@
|
|||||||
$('.expense_date .input-group-addon').click(function() {
|
$('.expense_date .input-group-addon').click(function() {
|
||||||
toggleDatePicker('expense_date');
|
toggleDatePicker('expense_date');
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
var $clientSelect = $('select#client');
|
||||||
|
for (var i=0; i<clients.length; i++) {
|
||||||
|
var client = clients[i];
|
||||||
|
$clientSelect.append(new Option(getClientDisplayName(client), client.public_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ({{ $clientPublicId ? 'true' : 'false' }}) {
|
||||||
|
$clientSelect.val({{ $clientPublicId }});
|
||||||
|
}
|
||||||
|
|
||||||
|
$clientSelect.combobox();
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@stop
|
@stop
|
@ -11,6 +11,9 @@
|
|||||||
@if ($entityType == ENTITY_TASK)
|
@if ($entityType == ENTITY_TASK)
|
||||||
{!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm("invoice")'])->appendIcon(Icon::create('check')) !!}
|
{!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm("invoice")'])->appendIcon(Icon::create('check')) !!}
|
||||||
@endif
|
@endif
|
||||||
|
@if ($entityType == ENTITY_EXPENSE)
|
||||||
|
{!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm("invoice")'])->appendIcon(Icon::create('check')) !!}
|
||||||
|
@endif
|
||||||
|
|
||||||
{!! DropdownButton::normal(trans('texts.archive'))->withContents([
|
{!! DropdownButton::normal(trans('texts.archive'))->withContents([
|
||||||
['label' => trans('texts.archive_'.$entityType), 'url' => 'javascript:submitForm("archive")'],
|
['label' => trans('texts.archive_'.$entityType), 'url' => 'javascript:submitForm("archive")'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user