mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 12:42:36 +01:00
Expense module
This commit is contained in:
parent
d89dc2e827
commit
d0bfe82512
@ -14,7 +14,7 @@ class ExpenseWasArchived extends Event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($espense)
|
||||
public function __construct($expense)
|
||||
{
|
||||
$this->expense = $expense;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ use Redirect;
|
||||
use Cache;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Client;
|
||||
use App\Services\ExpenseService;
|
||||
use App\Ninja\Repositories\ExpenseRepository;
|
||||
use App\Http\Requests\CreateExpenseRequest;
|
||||
@ -45,13 +46,14 @@ class ExpenseController extends BaseController
|
||||
'title' => trans('texts.expenses'),
|
||||
'sortCol' => '1',
|
||||
'columns' => Utils::trans([
|
||||
'checkbox',
|
||||
'vendor',
|
||||
'expense_amount',
|
||||
'expense_date',
|
||||
'public_notes',
|
||||
'is_invoiced',
|
||||
'should_be_invoiced',
|
||||
'expense'
|
||||
''
|
||||
]),
|
||||
));
|
||||
}
|
||||
@ -76,6 +78,8 @@ class ExpenseController extends BaseController
|
||||
'title' => trans('texts.new_expense'),
|
||||
'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(),
|
||||
'vendor' => $vendor,
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
|
||||
'clientPublicId' => null,
|
||||
);
|
||||
|
||||
$data = array_merge($data, self::getViewModel());
|
||||
@ -95,7 +99,9 @@ class ExpenseController extends BaseController
|
||||
'url' => 'expenses/'.$publicId,
|
||||
'title' => 'Edit Expense',
|
||||
'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());
|
||||
|
||||
|
@ -29,8 +29,8 @@ class ExpenseRepository extends BaseRepository
|
||||
$accountid = \Auth::user()->account_id;
|
||||
$query = DB::table('expenses')
|
||||
->join('accounts', 'accounts.id', '=', 'expenses.account_id')
|
||||
->leftjoin('vendors','vendors.public_id','=', 'expenses.vendor_id')
|
||||
->where('expenses.account_id', '=', $accountid)
|
||||
->where('expenses.deleted_at', '=', null)
|
||||
->select('expenses.account_id',
|
||||
'expenses.amount',
|
||||
'expenses.amount_cur',
|
||||
@ -45,12 +45,24 @@ class ExpenseRepository extends BaseRepository
|
||||
'expenses.public_id',
|
||||
'expenses.public_notes',
|
||||
'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')) {
|
||||
$query->where('expenses.deleted_at', '=', null);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
if ($filter) {
|
||||
$query->where(function ($query) use ($filter) {
|
||||
$query->where('expenses.public_notes', 'like', '%'.$filter.'%');
|
||||
@ -105,8 +117,10 @@ class ExpenseRepository extends BaseRepository
|
||||
// Calculate the amount cur
|
||||
$expense->amount_cur = ($expense->amount / 100) * $expense->exchange_rate;
|
||||
|
||||
|
||||
$expense->should_be_invoiced = isset($input['should_be_invoiced']) ? true : false;
|
||||
if(isset($input['client'])) {
|
||||
$expense->invoice_client_id = $input['client'];
|
||||
}
|
||||
$expense->save();
|
||||
|
||||
return $expense;
|
||||
|
@ -40,23 +40,15 @@ class ExpenseService extends BaseService
|
||||
{
|
||||
return [
|
||||
[
|
||||
'vendor_id',
|
||||
'vendor_name',
|
||||
function ($model)
|
||||
{
|
||||
if($model->vendor_id) {
|
||||
|
||||
$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;
|
||||
if($model->vendor_public_id) {
|
||||
return link_to("vendors/{$model->vendor_public_id}", $model->vendor_name);
|
||||
} else {
|
||||
return 'No vendor:' ;
|
||||
return 'No vendor' ;
|
||||
}
|
||||
},
|
||||
}
|
||||
],
|
||||
[
|
||||
'amount',
|
||||
@ -79,7 +71,7 @@ class ExpenseService extends BaseService
|
||||
[
|
||||
'is_invoiced',
|
||||
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');
|
||||
}
|
||||
],
|
||||
[
|
||||
/*[
|
||||
'public_id',
|
||||
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)
|
||||
{
|
||||
return [
|
||||
return [
|
||||
[
|
||||
trans('texts.apply_expense'),
|
||||
trans('texts.invoice_expense'),
|
||||
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
|
||||
'config' => false, // Display config settings
|
||||
'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->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->unsignedInteger('account_id')->index();
|
||||
$table->unsignedInteger('vendor_id')->nullable();
|
||||
$table->unsignedInteger('user_id');
|
||||
|
||||
$table->softDeletes();
|
||||
|
||||
$table->unsignedInteger('invoice_client_id')->nullable();
|
||||
$table->boolean('is_deleted')->default(false);
|
||||
$table->decimal('amount', 13, 2);
|
||||
$table->decimal('amount_cur', 13, 2);
|
||||
@ -36,9 +35,11 @@ class CreateExpensesTable extends Migration
|
||||
$table->boolean('is_invoiced')->default(false);
|
||||
$table->boolean('should_be_invoiced')->default(true);
|
||||
|
||||
// Relations
|
||||
$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->unique( array('account_id','public_id') );
|
||||
});
|
||||
|
@ -1047,11 +1047,15 @@ return array(
|
||||
'delete_expense' => 'Delete expense',
|
||||
'view_expense_num' => 'Expense # :expense',
|
||||
'updated_expense' => 'Expense updated',
|
||||
|
||||
'enter_expense' => 'Enter expense',
|
||||
'view' => 'View',
|
||||
'restore_expense' => 'Restore expense',
|
||||
'invoice_expense' => 'Invoice',
|
||||
// Payment terms
|
||||
'num_days' => 'Number of days',
|
||||
'create_payment_term' => 'Create payment term',
|
||||
'edit_payment_terms' => 'Edit payment term',
|
||||
'edit_payment_term' => 'Edit payment term',
|
||||
'archive_payment_term' => 'Archive payment term',
|
||||
|
||||
);
|
||||
|
@ -33,13 +33,14 @@
|
||||
{!! Former::textarea('private_notes') !!}
|
||||
{!! Former::textarea('public_notes') !!}
|
||||
{!! Former::checkbox('should_be_invoiced') !!}
|
||||
{!! Former::select('client')->addOption('', '')->addGroupClass('client-select') !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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')) !!}
|
||||
</center>
|
||||
|
||||
@ -49,6 +50,7 @@
|
||||
|
||||
|
||||
var vendors = {!! $vendors !!};
|
||||
var clients = {!! $clients !!};
|
||||
|
||||
$(function() {
|
||||
|
||||
@ -76,7 +78,20 @@
|
||||
$('.expense_date .input-group-addon').click(function() {
|
||||
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>
|
||||
@stop
|
@ -11,6 +11,9 @@
|
||||
@if ($entityType == ENTITY_TASK)
|
||||
{!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm("invoice")'])->appendIcon(Icon::create('check')) !!}
|
||||
@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([
|
||||
['label' => trans('texts.archive_'.$entityType), 'url' => 'javascript:submitForm("archive")'],
|
||||
|
Loading…
Reference in New Issue
Block a user