Working on recurring expenses

This commit is contained in:
Hillel Coren 2017-06-26 11:10:51 +03:00
parent 8675b25d1e
commit ffbe32256c
6 changed files with 46 additions and 20 deletions

View File

@ -51,6 +51,7 @@ class Expense extends EntityModel
'payment_type_id',
'transaction_reference',
'invoice_documents',
'should_be_invoiced',
];
public static function getImportColumns()

View File

@ -43,6 +43,10 @@ class RecurringExpense extends EntityModel
'tax_name1',
'tax_rate2',
'tax_name2',
'should_be_invoiced',
'start_date',
'end_date',
'frequency_id',
];
/**

View File

@ -91,6 +91,15 @@ class RecurringExpenseDatatable extends EntityDatatable
return $model->public_notes != null ? substr($model->public_notes, 0, 100) : '';
},
],
[
'frequency',
function ($model) {
$frequency = strtolower($model->frequency);
$frequency = preg_replace('/\s/', '_', $frequency);
return link_to("recurring_expenses/{$model->public_id}/edit", trans('texts.freq_'.$frequency))->toHtml();
},
],
];
}

View File

@ -176,8 +176,6 @@ class ExpenseRepository extends BaseRepository
$expense->payment_date = Utils::toSqlDate($input['payment_date']);
}
$expense->should_be_invoiced = isset($input['should_be_invoiced']) && floatval($input['should_be_invoiced']) || $expense->client_id ? true : false;
if (! $expense->expense_currency_id) {
$expense->expense_currency_id = \Auth::user()->account->getCurrencyId();
}
@ -195,7 +193,7 @@ class ExpenseRepository extends BaseRepository
// Documents
$document_ids = ! empty($input['document_ids']) ? array_map('intval', $input['document_ids']) : [];
;
foreach ($document_ids as $document_id) {
// check document completed upload before user submitted form
if ($document_id) {

View File

@ -33,6 +33,7 @@ class RecurringExpenseRepository extends BaseRepository
->leftjoin('clients', 'clients.id', '=', 'recurring_expenses.client_id')
->leftJoin('contacts', 'contacts.client_id', '=', 'clients.id')
->leftjoin('vendors', 'vendors.id', '=', 'recurring_expenses.vendor_id')
->join('frequencies', 'frequencies.id', '=', 'recurring_expenses.frequency_id')
->leftJoin('expense_categories', 'recurring_expenses.expense_category_id', '=', 'expense_categories.id')
->where('recurring_expenses.account_id', '=', $accountid)
->where('contacts.deleted_at', '=', null)
@ -58,6 +59,7 @@ class RecurringExpenseRepository extends BaseRepository
'recurring_expenses.user_id',
'recurring_expenses.tax_rate1',
'recurring_expenses.tax_rate2',
'frequencies.name as frequency',
'expense_categories.name as category',
'expense_categories.user_id as category_user_id',
'expense_categories.public_id as category_public_id',
@ -110,23 +112,21 @@ class RecurringExpenseRepository extends BaseRepository
// First auto fill
$expense->fill($input);
/*
if (isset($input['expense_date'])) {
$expense->expense_date = Utils::toSqlDate($input['expense_date']);
if (isset($input['start_date'])) {
$expense->start_date = Utils::toSqlDate($input['start_date']);
}
if (isset($input['payment_date'])) {
$expense->payment_date = Utils::toSqlDate($input['payment_date']);
if (isset($input['end_date'])) {
$expense->end_date = Utils::toSqlDate($input['end_date']);
}
$expense->should_be_invoiced = isset($input['should_be_invoiced']) && floatval($input['should_be_invoiced']) || $expense->client_id ? true : false;
if (! $expense->expense_currency_id) {
$expense->expense_currency_id = \Auth::user()->account->getCurrencyId();
}
/*
if (! $expense->invoice_currency_id) {
$expense->invoice_currency_id = \Auth::user()->account->getCurrencyId();
}
$rate = isset($input['exchange_rate']) ? Utils::parseFloat($input['exchange_rate']) : 1;
$expense->exchange_rate = round($rate, 4);
if (isset($input['amount'])) {

View File

@ -58,11 +58,13 @@
->data_placeholder(Utils::getFromCache($account->getCurrencyId(), 'currencies')->name)
->fromQuery($currencies, 'name', 'id') !!}
@if (! $isRecurring)
{!! Former::text('expense_date')
->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))
->addGroupClass('expense_date')
->label(trans('texts.date'))
->append('<i class="glyphicon glyphicon-calendar"></i>') !!}
@endif
@if ($expense && $expense->invoice_id)
{!! Former::plaintext()
@ -191,8 +193,8 @@
</div>
<div class="col-md-6">
{!! Former::textarea('public_notes')->rows(6) !!}
{!! Former::textarea('private_notes')->rows(6) !!}
{!! Former::textarea('public_notes')->rows($isRecurring ? 10 : 6) !!}
{!! Former::textarea('private_notes')->rows($isRecurring ? 10 : 6) !!}
@if (! $isRecurring && $account->hasFeature(FEATURE_DOCUMENTS))
<div class="form-group">
@ -371,7 +373,15 @@
$('#amount').focus();
@endif
@if (! $isRecurring && Auth::user()->account->hasFeature(FEATURE_DOCUMENTS))
@if ($isRecurring)
$('#start_date, #end_date').datepicker();
@if ($expense && $expense->start_date)
$('#start_date').datepicker('update', '{{ Utils::fromSqlDate($expense->start_date) }}');
@endif
@if ($expense && $expense->end_date)
$('#end_date').datepicker('update', '{{ Utils::fromSqlDate($expense->end_date) }}');
@endif
@elseif (Auth::user()->account->hasFeature(FEATURE_DOCUMENTS))
$('.main-form').submit(function(){
if($('#document-upload .fallback input').val())$(this).attr('enctype', 'multipart/form-data')
else $(this).removeAttr('enctype')
@ -457,7 +467,11 @@
self.should_be_invoiced = ko.observable();
self.apply_taxes = ko.observable({{ ($expense && ($expense->tax_name1 || $expense->tax_name2)) ? 'true' : 'false' }});
@if (! $isRecurring)
@if ($isRecurring)
self.frequency_id = ko.observable();
self.start_date = ko.observable();
self.end_date = ko.observable();
@else
self.convert_currency = ko.observable({{ ($expense && $expense->isExchanged()) ? 'true' : 'false' }});
self.mark_paid = ko.observable({{ $expense && $expense->isPaid() ? 'true' : 'false' }});
@endif