2016-01-08 19:01:00 +01:00
|
|
|
@extends('header')
|
|
|
|
|
2016-01-20 23:09:10 +01:00
|
|
|
@section('head')
|
|
|
|
@parent
|
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
@include('money_script')
|
2016-02-01 23:12:42 +01:00
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
.input-group-addon {
|
|
|
|
min-width: 40px;
|
|
|
|
}
|
|
|
|
</style>
|
2016-01-20 23:09:10 +01:00
|
|
|
@stop
|
|
|
|
|
2016-01-08 19:01:00 +01:00
|
|
|
@section('content')
|
2016-05-15 22:16:08 +02:00
|
|
|
|
2016-05-25 21:01:15 +02:00
|
|
|
{!! Former::open($url)
|
|
|
|
->addClass('warn-on-exit main-form')
|
|
|
|
->onsubmit('return onFormSubmit(event)')
|
2018-03-14 12:03:30 +01:00
|
|
|
->autocomplete('off')
|
2016-05-25 21:01:15 +02:00
|
|
|
->method($method) !!}
|
2016-01-21 23:29:10 +01:00
|
|
|
<div style="display:none">
|
|
|
|
{!! Former::text('action') !!}
|
2017-01-29 21:51:12 +01:00
|
|
|
{!! Former::text('data')->data_bind('value: ko.mapping.toJSON(model)') !!}
|
2016-01-21 23:29:10 +01:00
|
|
|
</div>
|
2016-01-08 19:01:00 +01:00
|
|
|
|
|
|
|
@if ($expense)
|
|
|
|
{!! Former::populate($expense) !!}
|
2016-01-20 23:09:10 +01:00
|
|
|
{!! Former::populateField('should_be_invoiced', intval($expense->should_be_invoiced)) !!}
|
2016-08-21 17:25:35 +02:00
|
|
|
|
|
|
|
<div style="display:none">
|
|
|
|
{!! Former::text('public_id') !!}
|
|
|
|
{!! Former::text('invoice_id') !!}
|
|
|
|
</div>
|
2016-01-08 19:01:00 +01:00
|
|
|
@endif
|
|
|
|
|
2016-01-20 23:09:10 +01:00
|
|
|
<div class="panel panel-default">
|
|
|
|
<div class="panel-body">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6">
|
2016-07-05 20:49:47 +02:00
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
{!! Former::select('vendor_id')->addOption('', '')
|
|
|
|
->label(trans('texts.vendor'))
|
2016-01-20 23:09:10 +01:00
|
|
|
->addGroupClass('vendor-select') !!}
|
2016-01-21 20:15:30 +01:00
|
|
|
|
2016-07-07 10:03:43 +02:00
|
|
|
{!! Former::select('expense_category_id')->addOption('', '')
|
|
|
|
->label(trans('texts.category'))
|
2017-03-02 17:02:48 +01:00
|
|
|
->addGroupClass('expense-category-select') !!}
|
2016-07-05 20:49:47 +02:00
|
|
|
|
2017-03-03 11:06:21 +01:00
|
|
|
{!! Former::text('amount')
|
|
|
|
->label(trans('texts.amount'))
|
|
|
|
->data_bind("value: amount, valueUpdate: 'afterkeydown'")
|
|
|
|
->addGroupClass('amount')
|
|
|
|
->append('<span data-bind="html: expenseCurrencyCode"></span>') !!}
|
2016-01-21 20:15:30 +01:00
|
|
|
|
2016-02-01 23:07:09 +01:00
|
|
|
{!! Former::select('expense_currency_id')->addOption('','')
|
|
|
|
->data_bind('combobox: expense_currency_id')
|
|
|
|
->label(trans('texts.currency_id'))
|
2017-12-07 11:33:46 +01:00
|
|
|
->data_placeholder(Utils::getFromCache($account->getCurrencyId(), 'currencies')->getTranslatedName())
|
2016-02-01 23:07:09 +01:00
|
|
|
->fromQuery($currencies, 'name', 'id') !!}
|
|
|
|
|
2017-06-26 10:10:51 +02:00
|
|
|
@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
|
2016-02-01 23:07:09 +01:00
|
|
|
|
2016-12-19 19:39:48 +01:00
|
|
|
@if ($expense && $expense->invoice_id)
|
|
|
|
{!! Former::plaintext()
|
|
|
|
->label('client')
|
2017-03-19 17:35:33 +01:00
|
|
|
->value($expense->client->present()->link) !!}
|
2016-12-19 19:39:48 +01:00
|
|
|
@else
|
|
|
|
{!! Former::select('client_id')
|
|
|
|
->addOption('', '')
|
|
|
|
->label(trans('texts.client'))
|
|
|
|
->data_bind('combobox: client_id')
|
|
|
|
->addGroupClass('client-select') !!}
|
|
|
|
@endif
|
2016-01-21 20:15:30 +01:00
|
|
|
|
2018-04-04 21:08:37 +02:00
|
|
|
@include('partials/custom_fields', ['entityType' => ENTITY_EXPENSE])
|
|
|
|
|
2017-06-26 06:16:29 +02:00
|
|
|
@if (count($taxRates))
|
|
|
|
@if (!$expense || ($expense && (!$expense->tax_name1 && !$expense->tax_name2)))
|
|
|
|
{!! Former::checkbox('apply_taxes')
|
|
|
|
->text(trans('texts.apply_taxes'))
|
|
|
|
->data_bind('checked: apply_taxes')
|
|
|
|
->label(' ')
|
|
|
|
->value(1) !!}
|
|
|
|
@endif
|
|
|
|
@endif
|
|
|
|
|
|
|
|
<div style="display:none" data-bind="visible: apply_taxes">
|
|
|
|
<br/>
|
|
|
|
@include('partials.tax_rates')
|
|
|
|
</div>
|
|
|
|
|
2017-03-19 17:35:33 +01:00
|
|
|
@if (!$expense || ($expense && !$expense->invoice_id))
|
2016-01-21 21:36:49 +01:00
|
|
|
{!! Former::checkbox('should_be_invoiced')
|
2017-04-19 16:18:24 +02:00
|
|
|
->text(trans('texts.mark_billable'))
|
2017-03-19 17:35:33 +01:00
|
|
|
->data_bind('checked: should_be_invoiced()')
|
2017-01-09 16:01:51 +01:00
|
|
|
->label(' ')
|
|
|
|
->value(1) !!}
|
2016-01-21 21:36:49 +01:00
|
|
|
@endif
|
2016-01-21 20:15:30 +01:00
|
|
|
|
2017-06-26 06:16:29 +02:00
|
|
|
@if ($isRecurring)
|
|
|
|
|
|
|
|
{!! Former::select('frequency_id')
|
|
|
|
->label('frequency')
|
|
|
|
->options(\App\Models\Frequency::selectOptions())
|
|
|
|
->data_bind("value: frequency_id") !!}
|
|
|
|
{!! Former::text('start_date')
|
|
|
|
->data_bind("datePicker: start_date, valueUpdate: 'afterkeydown'")
|
|
|
|
->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))
|
|
|
|
->appendIcon('calendar')
|
2018-04-10 21:53:39 +02:00
|
|
|
->addGroupClass('start_date')
|
2018-05-14 08:20:15 +02:00
|
|
|
->data_date_start_date($expense ? false : $account->formatDate($account->getDateTime())) !!}
|
2017-06-26 06:16:29 +02:00
|
|
|
{!! Former::text('end_date')
|
|
|
|
->data_bind("datePicker: end_date, valueUpdate: 'afterkeydown'")
|
|
|
|
->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))
|
|
|
|
->appendIcon('calendar')
|
2018-04-10 21:53:39 +02:00
|
|
|
->addGroupClass('end_date')
|
2018-05-14 08:20:15 +02:00
|
|
|
->data_date_start_date($expense ? false : $account->formatDate($account->getDateTime())) !!}
|
2017-04-19 16:18:24 +02:00
|
|
|
|
2017-06-26 06:16:29 +02:00
|
|
|
@else
|
|
|
|
@if ((! $expense || ! $expense->transaction_id))
|
|
|
|
|
|
|
|
@if (! $expense || ! $expense->isPaid())
|
|
|
|
{!! Former::checkbox('mark_paid')
|
|
|
|
->data_bind('checked: mark_paid')
|
|
|
|
->text(trans('texts.mark_expense_paid'))
|
|
|
|
->label(' ')
|
|
|
|
->value(1) !!}
|
|
|
|
@endif
|
|
|
|
|
|
|
|
<div style="display:none" data-bind="visible: mark_paid">
|
|
|
|
{!! Former::select('payment_type_id')
|
|
|
|
->addOption('','')
|
|
|
|
->fromQuery($paymentTypes, 'name', 'id')
|
|
|
|
->addGroupClass('payment-type-select') !!}
|
|
|
|
|
|
|
|
{!! Former::text('payment_date')
|
|
|
|
->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT))
|
|
|
|
->addGroupClass('payment_date')
|
|
|
|
->append('<i class="glyphicon glyphicon-calendar"></i>') !!}
|
|
|
|
|
|
|
|
{!! Former::text('transaction_reference') !!}
|
|
|
|
</div>
|
|
|
|
@endif
|
|
|
|
|
|
|
|
@if (!$expense || ($expense && ! $expense->isExchanged()))
|
|
|
|
{!! Former::checkbox('convert_currency')
|
|
|
|
->text(trans('texts.convert_currency'))
|
|
|
|
->data_bind('checked: convert_currency')
|
2017-04-19 16:18:24 +02:00
|
|
|
->label(' ')
|
|
|
|
->value(1) !!}
|
|
|
|
@endif
|
|
|
|
|
|
|
|
|
2017-06-26 06:16:29 +02:00
|
|
|
<div style="display:none" data-bind="visible: enableExchangeRate">
|
|
|
|
<br/>
|
|
|
|
<span style="display:none" data-bind="visible: !client_id()">
|
|
|
|
{!! Former::select('invoice_currency_id')->addOption('','')
|
|
|
|
->label(trans('texts.invoice_currency'))
|
|
|
|
->data_placeholder(Utils::getFromCache($account->getCurrencyId(), 'currencies')->name)
|
2017-12-21 08:47:17 +01:00
|
|
|
->data_bind('combobox: invoice_currency_id, disable: true')
|
2017-06-26 06:16:29 +02:00
|
|
|
->fromQuery($currencies, 'name', 'id') !!}
|
|
|
|
</span>
|
|
|
|
<span style="display:none;" data-bind="visible: client_id">
|
|
|
|
{!! Former::plaintext('')
|
|
|
|
->value('<span data-bind="html: invoiceCurrencyName"></span>')
|
|
|
|
->style('min-height:46px')
|
|
|
|
->label(trans('texts.invoice_currency')) !!}
|
|
|
|
</span>
|
|
|
|
|
|
|
|
{!! Former::text('exchange_rate')
|
|
|
|
->data_bind("value: exchange_rate, enable: enableExchangeRate, valueUpdate: 'afterkeydown'") !!}
|
|
|
|
|
|
|
|
{!! Former::text('invoice_amount')
|
|
|
|
->addGroupClass('converted-amount')
|
|
|
|
->data_bind("value: convertedAmount, enable: enableExchangeRate")
|
|
|
|
->append('<span data-bind="html: invoiceCurrencyCode"></span>') !!}
|
2017-04-19 16:18:24 +02:00
|
|
|
</div>
|
2016-07-07 18:54:06 +02:00
|
|
|
|
2017-06-26 06:16:29 +02:00
|
|
|
@if ($account->hasFeature(FEATURE_DOCUMENTS))
|
|
|
|
{!! Former::checkbox('invoice_documents')
|
|
|
|
->text(trans('texts.add_documents_to_invoice'))
|
|
|
|
->onchange('onInvoiceDocumentsChange()')
|
|
|
|
->data_bind('checked: invoice_documents')
|
2017-04-18 08:31:44 +02:00
|
|
|
->label(' ')
|
|
|
|
->value(1) !!}
|
|
|
|
@endif
|
|
|
|
|
2017-04-28 15:42:19 +02:00
|
|
|
@endif
|
|
|
|
|
2017-06-26 06:16:29 +02:00
|
|
|
|
2016-01-08 19:01:00 +01:00
|
|
|
</div>
|
2016-01-20 23:09:10 +01:00
|
|
|
<div class="col-md-6">
|
|
|
|
|
2017-08-07 17:09:41 +02:00
|
|
|
{!! Former::textarea('private_notes')->rows(! $isRecurring && $account->hasFeature(FEATURE_DOCUMENTS) ? 6 : 10) !!}
|
|
|
|
{!! Former::textarea('public_notes')->rows(! $isRecurring && $account->hasFeature(FEATURE_DOCUMENTS) ? 6 : 10) !!}
|
2017-03-02 17:02:48 +01:00
|
|
|
|
2017-06-26 06:16:29 +02:00
|
|
|
@if (! $isRecurring && $account->hasFeature(FEATURE_DOCUMENTS))
|
2017-03-02 17:02:48 +01:00
|
|
|
<div class="form-group">
|
|
|
|
<label for="public_notes" class="control-label col-lg-4 col-sm-4">
|
|
|
|
{{trans('texts.documents')}}
|
|
|
|
</label>
|
|
|
|
<div class="col-lg-8 col-sm-8">
|
|
|
|
<div role="tabpanel" class="tab-pane" id="attached-documents" style="position:relative;z-index:9">
|
2017-07-20 21:45:10 +02:00
|
|
|
<div id="document-upload">
|
|
|
|
<div class="dropzone">
|
|
|
|
<div data-bind="foreach: documents">
|
|
|
|
<input type="hidden" name="document_ids[]" data-bind="value: public_id"/>
|
|
|
|
</div>
|
2017-03-02 17:02:48 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-03-24 23:15:52 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-03-02 17:02:48 +01:00
|
|
|
@endif
|
|
|
|
|
2016-03-24 23:15:52 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2016-01-08 19:01:00 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2016-10-10 10:40:04 +02:00
|
|
|
<center class="buttons">
|
|
|
|
{!! Button::normal(trans('texts.cancel'))
|
2017-06-13 14:42:41 +02:00
|
|
|
->asLinkTo(HTMLUtils::previousUrl('/expenses'))
|
2016-10-10 10:40:04 +02:00
|
|
|
->appendIcon(Icon::create('remove-circle'))
|
|
|
|
->large() !!}
|
2016-09-20 16:34:13 +02:00
|
|
|
|
2016-10-10 10:40:04 +02:00
|
|
|
@if (Auth::user()->canCreateOrEdit(ENTITY_EXPENSE, $expense))
|
2016-09-20 16:34:13 +02:00
|
|
|
@if (Auth::user()->hasFeature(FEATURE_EXPENSES))
|
2016-10-10 10:40:04 +02:00
|
|
|
@if (!$expense || !$expense->is_deleted)
|
|
|
|
{!! Button::success(trans('texts.save'))
|
|
|
|
->appendIcon(Icon::create('floppy-disk'))
|
|
|
|
->large()
|
|
|
|
->submit() !!}
|
|
|
|
@endif
|
2016-09-20 16:34:13 +02:00
|
|
|
|
2016-10-10 10:40:04 +02:00
|
|
|
@if ($expense && !$expense->trashed())
|
2016-09-20 16:34:13 +02:00
|
|
|
{!! DropdownButton::normal(trans('texts.more_actions'))
|
|
|
|
->withContents($actions)
|
|
|
|
->large()
|
|
|
|
->dropup() !!}
|
|
|
|
@endif
|
2016-10-10 10:40:04 +02:00
|
|
|
|
|
|
|
@if ($expense && $expense->trashed())
|
|
|
|
{!! Button::primary(trans('texts.restore'))
|
|
|
|
->withAttributes(['onclick' => 'submitAction("restore")'])
|
|
|
|
->appendIcon(Icon::create('cloud-download'))
|
|
|
|
->large() !!}
|
|
|
|
@endif
|
|
|
|
|
2016-07-11 19:08:43 +02:00
|
|
|
@endif
|
2016-10-10 10:40:04 +02:00
|
|
|
@endif
|
|
|
|
</center>
|
2016-01-08 19:01:00 +01:00
|
|
|
|
|
|
|
{!! Former::close() !!}
|
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
<script type="text/javascript">
|
2017-05-08 21:10:39 +02:00
|
|
|
var vendors = {!! $vendors !!};
|
|
|
|
var clients = {!! $clients !!};
|
|
|
|
var categories = {!! $categories !!};
|
2016-01-09 06:24:43 +01:00
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
var clientMap = {};
|
2017-03-02 17:02:48 +01:00
|
|
|
var vendorMap = {};
|
|
|
|
var categoryMap = {};
|
|
|
|
|
2016-01-09 06:24:43 +01:00
|
|
|
for (var i=0; i<clients.length; i++) {
|
|
|
|
var client = clients[i];
|
2016-01-21 20:15:30 +01:00
|
|
|
clientMap[client.public_id] = client;
|
|
|
|
}
|
2016-01-09 06:24:43 +01:00
|
|
|
|
2016-05-25 21:01:15 +02:00
|
|
|
function onFormSubmit(event) {
|
|
|
|
if (window.countUploadingDocuments > 0) {
|
2018-03-27 11:52:37 +02:00
|
|
|
swal({!! json_encode(trans('texts.wait_for_upload')) !!});
|
2016-05-25 21:01:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-20 16:34:13 +02:00
|
|
|
@if (Auth::user()->canCreateOrEdit(ENTITY_EXPENSE, $expense))
|
|
|
|
return true;
|
|
|
|
@else
|
|
|
|
return false
|
|
|
|
@endif
|
2016-05-25 21:01:15 +02:00
|
|
|
}
|
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
function onClientChange() {
|
|
|
|
var clientId = $('select#client_id').val();
|
|
|
|
var client = clientMap[clientId];
|
|
|
|
if (client) {
|
2016-02-01 23:07:09 +01:00
|
|
|
model.invoice_currency_id(client.currency_id);
|
2018-04-05 13:39:54 +02:00
|
|
|
model.updateExchangeRate();
|
2016-01-21 20:15:30 +01:00
|
|
|
}
|
2016-01-09 06:24:43 +01:00
|
|
|
}
|
|
|
|
|
2016-08-21 17:25:35 +02:00
|
|
|
function submitAction(action, invoice_id) {
|
2016-01-21 23:29:10 +01:00
|
|
|
$('#action').val(action);
|
2016-08-21 17:25:35 +02:00
|
|
|
$('#invoice_id').val(invoice_id);
|
2016-01-21 23:29:10 +01:00
|
|
|
$('.main-form').submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDeleteClick() {
|
2016-07-28 18:55:23 +02:00
|
|
|
sweetConfirm(function() {
|
2016-01-21 23:29:10 +01:00
|
|
|
submitAction('delete');
|
2016-07-28 18:55:23 +02:00
|
|
|
});
|
2016-01-21 23:29:10 +01:00
|
|
|
}
|
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
$(function() {
|
2017-03-02 17:02:48 +01:00
|
|
|
var vendorId = {{ $vendorPublicId ?: 0 }};
|
2016-01-21 20:15:30 +01:00
|
|
|
var $vendorSelect = $('select#vendor_id');
|
2017-03-02 17:02:48 +01:00
|
|
|
@if (Auth::user()->can('create', ENTITY_VENDOR))
|
|
|
|
$vendorSelect.append(new Option("{{ trans('texts.create_vendor')}}: $name", '-1'));
|
|
|
|
@endif
|
2016-01-21 20:15:30 +01:00
|
|
|
for (var i = 0; i < vendors.length; i++) {
|
|
|
|
var vendor = vendors[i];
|
2017-03-02 17:02:48 +01:00
|
|
|
vendorMap[vendor.public_id] = vendor;
|
2016-01-21 20:15:30 +01:00
|
|
|
$vendorSelect.append(new Option(getClientDisplayName(vendor), vendor.public_id));
|
|
|
|
}
|
2017-03-02 17:02:48 +01:00
|
|
|
@include('partials/entity_combobox', ['entityType' => ENTITY_VENDOR])
|
|
|
|
if (vendorId) {
|
|
|
|
var vendor = vendorMap[vendorId];
|
|
|
|
setComboboxValue($('.vendor-select'), vendor.public_id, vendor.name);
|
|
|
|
}
|
2016-01-21 20:15:30 +01:00
|
|
|
|
2017-03-02 17:02:48 +01:00
|
|
|
var categoryId = {{ $categoryPublicId ?: 0 }};
|
|
|
|
var $expense_categorySelect = $('select#expense_category_id');
|
|
|
|
@if (Auth::user()->can('create', ENTITY_EXPENSE_CATEGORY))
|
|
|
|
$expense_categorySelect.append(new Option("{{ trans('texts.create_expense_category')}}: $name", '-1'));
|
|
|
|
@endif
|
2016-07-07 10:03:43 +02:00
|
|
|
for (var i = 0; i < categories.length; i++) {
|
|
|
|
var category = categories[i];
|
2017-03-02 17:02:48 +01:00
|
|
|
categoryMap[category.public_id] = category;
|
|
|
|
$expense_categorySelect.append(new Option(category.name, category.public_id));
|
|
|
|
}
|
|
|
|
@include('partials/entity_combobox', ['entityType' => ENTITY_EXPENSE_CATEGORY])
|
|
|
|
if (categoryId) {
|
|
|
|
var category = categoryMap[categoryId];
|
|
|
|
setComboboxValue($('.expense-category-select'), category.public_id, category.name);
|
2016-07-07 10:03:43 +02:00
|
|
|
}
|
|
|
|
|
2017-04-19 16:18:24 +02:00
|
|
|
$('#expense_date').datepicker('update', '{{ $expense ? Utils::fromSqlDate($expense->expense_date) : 'new Date()' }}');
|
2016-01-21 20:15:30 +01:00
|
|
|
|
|
|
|
$('.expense_date .input-group-addon').click(function() {
|
|
|
|
toggleDatePicker('expense_date');
|
|
|
|
});
|
|
|
|
|
|
|
|
var $clientSelect = $('select#client_id');
|
|
|
|
for (var i=0; i<clients.length; i++) {
|
|
|
|
var client = clients[i];
|
2016-07-13 11:03:39 +02:00
|
|
|
var clientName = getClientDisplayName(client);
|
|
|
|
if (!clientName) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$clientSelect.append(new Option(clientName, client.public_id));
|
2016-01-21 20:15:30 +01:00
|
|
|
}
|
2017-10-30 15:00:55 +01:00
|
|
|
$clientSelect.combobox({highlighter: comboboxHighlighter}).change(function() {
|
2016-01-21 20:15:30 +01:00
|
|
|
onClientChange();
|
|
|
|
});
|
|
|
|
|
2017-12-21 08:47:17 +01:00
|
|
|
$('#invoice_currency_id, #expense_currency_id').on('change', function() {
|
|
|
|
setTimeout(function() {
|
|
|
|
model.updateExchangeRate();
|
|
|
|
}, 1);
|
|
|
|
})
|
|
|
|
|
2016-01-21 21:36:49 +01:00
|
|
|
@if ($data)
|
|
|
|
// this means we failed so we'll reload the previous state
|
|
|
|
window.model = new ViewModel({!! $data !!});
|
|
|
|
@else
|
|
|
|
// otherwise create blank model
|
|
|
|
window.model = new ViewModel({!! $expense !!});
|
|
|
|
@endif
|
2017-01-29 21:51:12 +01:00
|
|
|
ko.applyBindings(model);
|
2016-01-21 20:15:30 +01:00
|
|
|
|
|
|
|
@if (!$expense && $clientPublicId)
|
|
|
|
onClientChange();
|
|
|
|
@endif
|
|
|
|
|
|
|
|
@if (!$vendorPublicId)
|
|
|
|
$('.vendor-select input.form-control').focus();
|
|
|
|
@else
|
|
|
|
$('#amount').focus();
|
|
|
|
@endif
|
2016-05-15 22:16:08 +02:00
|
|
|
|
2017-06-26 10:10:51 +02:00
|
|
|
@if ($isRecurring)
|
|
|
|
$('#start_date, #end_date').datepicker();
|
|
|
|
@if ($expense && $expense->start_date)
|
2017-06-26 15:25:11 +02:00
|
|
|
$('#start_date').datepicker('update', '{{ $expense && $expense->start_date ? Utils::fromSqlDate($expense->start_date) : 'new Date()' }}');
|
|
|
|
@elseif (! $expense)
|
|
|
|
$('#start_date').datepicker('update', new Date());
|
2017-06-26 10:10:51 +02:00
|
|
|
@endif
|
|
|
|
@if ($expense && $expense->end_date)
|
|
|
|
$('#end_date').datepicker('update', '{{ Utils::fromSqlDate($expense->end_date) }}');
|
|
|
|
@endif
|
2017-06-26 15:25:11 +02:00
|
|
|
|
|
|
|
$('.start_date .input-group-addon').click(function() {
|
|
|
|
toggleDatePicker('start_date');
|
|
|
|
});
|
|
|
|
$('.end_date .input-group-addon').click(function() {
|
|
|
|
toggleDatePicker('end_date');
|
|
|
|
});
|
2017-07-21 16:24:03 +02:00
|
|
|
@else
|
2017-06-26 06:16:29 +02:00
|
|
|
$('#payment_type_id').combobox();
|
|
|
|
$('#mark_paid').click(function(event) {
|
|
|
|
if ($('#mark_paid').is(':checked')) {
|
|
|
|
$('#payment_date').datepicker('update', new Date());
|
|
|
|
@if ($account->payment_type_id)
|
|
|
|
setComboboxValue($('.payment-type-select'), {{ $account->payment_type_id }}, "{{ trans('texts.payment_type_' . $account->payment_type->name) }}");
|
|
|
|
@endif
|
|
|
|
} else {
|
|
|
|
$('#payment_date').datepicker('update', false);
|
|
|
|
setComboboxValue($('.payment-type-select'), '', '');
|
|
|
|
}
|
|
|
|
})
|
2017-04-19 16:18:24 +02:00
|
|
|
|
2017-06-26 06:16:29 +02:00
|
|
|
@if ($expense && $expense->payment_date)
|
|
|
|
$('#payment_date').datepicker('update', '{{ Utils::fromSqlDate($expense->payment_date) }}');
|
|
|
|
@endif
|
2017-06-13 19:41:35 +02:00
|
|
|
|
2017-06-26 06:16:29 +02:00
|
|
|
$('.payment_date .input-group-addon').click(function() {
|
|
|
|
toggleDatePicker('payment_date');
|
|
|
|
});
|
|
|
|
|
2017-07-21 16:24:03 +02:00
|
|
|
@if (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')
|
|
|
|
})
|
2017-07-20 21:45:10 +02:00
|
|
|
|
2017-07-21 16:24:03 +02:00
|
|
|
@include('partials.dropzone', ['documentSource' => 'model.documents()'])
|
|
|
|
@endif
|
2016-03-24 23:15:52 +01:00
|
|
|
@endif
|
2016-01-21 20:15:30 +01:00
|
|
|
});
|
|
|
|
|
2016-01-21 21:36:49 +01:00
|
|
|
var ViewModel = function(data) {
|
2016-01-21 20:15:30 +01:00
|
|
|
var self = this;
|
|
|
|
|
2016-02-01 23:07:09 +01:00
|
|
|
self.expense_currency_id = ko.observable();
|
|
|
|
self.invoice_currency_id = ko.observable();
|
2016-03-25 00:55:56 +01:00
|
|
|
self.documents = ko.observableArray();
|
2016-01-21 21:36:49 +01:00
|
|
|
self.amount = ko.observable();
|
|
|
|
self.exchange_rate = ko.observable(1);
|
|
|
|
self.should_be_invoiced = ko.observable();
|
2016-07-07 18:54:06 +02:00
|
|
|
self.apply_taxes = ko.observable({{ ($expense && ($expense->tax_name1 || $expense->tax_name2)) ? 'true' : 'false' }});
|
2016-01-21 20:15:30 +01:00
|
|
|
|
2017-06-26 10:10:51 +02:00
|
|
|
@if ($isRecurring)
|
2017-06-26 16:19:44 +02:00
|
|
|
self.frequency_id = ko.observable({{ FREQUENCY_MONTHLY }});
|
2017-06-26 10:10:51 +02:00
|
|
|
self.start_date = ko.observable();
|
|
|
|
self.end_date = ko.observable();
|
|
|
|
@else
|
2017-06-26 06:16:29 +02:00
|
|
|
self.convert_currency = ko.observable({{ ($expense && $expense->isExchanged()) ? 'true' : 'false' }});
|
|
|
|
self.mark_paid = ko.observable({{ $expense && $expense->isPaid() ? 'true' : 'false' }});
|
|
|
|
@endif
|
|
|
|
|
2017-04-28 15:42:19 +02:00
|
|
|
var invoiceDocuments = false;
|
|
|
|
if (isStorageSupported()) {
|
|
|
|
invoiceDocuments = localStorage.getItem('last:invoice_documents');
|
|
|
|
}
|
|
|
|
self.invoice_documents = ko.observable({{ $expense ? $expense->invoice_documents : 'invoiceDocuments' }});
|
|
|
|
|
2016-03-24 23:15:52 +01:00
|
|
|
self.mapping = {
|
|
|
|
'documents': {
|
|
|
|
create: function(options) {
|
|
|
|
return new DocumentModel(options.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-15 22:16:08 +02:00
|
|
|
|
2016-01-21 21:36:49 +01:00
|
|
|
if (data) {
|
2016-03-24 23:15:52 +01:00
|
|
|
ko.mapping.fromJS(data, self.mapping, this);
|
2016-01-21 21:36:49 +01:00
|
|
|
}
|
|
|
|
|
2017-03-13 10:15:05 +01:00
|
|
|
self.account_currency_id = ko.observable({{ $account->getCurrencyId() }});
|
|
|
|
self.client_id = ko.observable({{ $clientPublicId }});
|
|
|
|
//self.vendor_id = ko.observable({{ $vendorPublicId }});
|
|
|
|
//self.expense_category_id = ko.observable({{ $categoryPublicId }});
|
|
|
|
|
2016-01-21 21:36:49 +01:00
|
|
|
self.convertedAmount = ko.computed({
|
|
|
|
read: function () {
|
|
|
|
return roundToTwo(self.amount() * self.exchange_rate()).toFixed(2);
|
|
|
|
},
|
|
|
|
write: function(value) {
|
2017-11-17 12:56:10 +01:00
|
|
|
// When changing the converted amount we're updating
|
|
|
|
// the exchange rate rather than change the amount
|
2018-01-01 10:15:49 +01:00
|
|
|
self.exchange_rate(roundSignificant(NINJA.parseFloat(value) / self.amount()));
|
2017-11-17 12:56:10 +01:00
|
|
|
//self.amount(roundToTwo(value / self.exchange_rate()));
|
2016-01-21 21:36:49 +01:00
|
|
|
}
|
|
|
|
}, self);
|
|
|
|
|
2017-12-21 08:47:17 +01:00
|
|
|
self.updateExchangeRate = function() {
|
|
|
|
var fromCode = self.expenseCurrencyCode();
|
|
|
|
var toCode = self.invoiceCurrencyCode();
|
|
|
|
if (currencyMap[fromCode].exchange_rate && currencyMap[toCode].exchange_rate) {
|
|
|
|
var rate = fx.convert(1, {
|
|
|
|
from: fromCode,
|
|
|
|
to: toCode,
|
|
|
|
});
|
|
|
|
self.exchange_rate(roundToFour(rate, true));
|
|
|
|
} else {
|
|
|
|
self.exchange_rate(1);
|
2017-12-20 21:36:29 +01:00
|
|
|
}
|
2017-12-21 08:47:17 +01:00
|
|
|
}
|
2017-12-20 21:36:29 +01:00
|
|
|
|
2016-02-01 23:07:09 +01:00
|
|
|
self.getCurrency = function(currencyId) {
|
|
|
|
return currencyMap[currencyId || self.account_currency_id()];
|
|
|
|
};
|
|
|
|
|
|
|
|
self.expenseCurrencyCode = ko.computed(function() {
|
|
|
|
return self.getCurrency(self.expense_currency_id()).code;
|
|
|
|
});
|
|
|
|
|
|
|
|
self.invoiceCurrencyCode = ko.computed(function() {
|
|
|
|
return self.getCurrency(self.invoice_currency_id()).code;
|
2016-01-21 20:15:30 +01:00
|
|
|
});
|
|
|
|
|
2016-02-01 23:07:09 +01:00
|
|
|
self.invoiceCurrencyName = ko.computed(function() {
|
|
|
|
return self.getCurrency(self.invoice_currency_id()).name;
|
2016-01-21 20:15:30 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
self.enableExchangeRate = ko.computed(function() {
|
2017-06-26 06:16:29 +02:00
|
|
|
if (self.convert_currency && self.convert_currency()) {
|
2016-02-17 12:06:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
2016-02-01 23:07:09 +01:00
|
|
|
var expenseCurrencyId = self.expense_currency_id() || self.account_currency_id();
|
|
|
|
var invoiceCurrencyId = self.invoice_currency_id() || self.account_currency_id();
|
2016-05-15 22:16:08 +02:00
|
|
|
return expenseCurrencyId != invoiceCurrencyId
|
2016-02-17 12:06:03 +01:00
|
|
|
|| invoiceCurrencyId != self.account_currency_id()
|
|
|
|
|| expenseCurrencyId != self.account_currency_id();
|
2016-01-21 20:15:30 +01:00
|
|
|
})
|
2016-05-15 22:16:08 +02:00
|
|
|
|
2016-03-24 23:15:52 +01:00
|
|
|
self.addDocument = function() {
|
|
|
|
var documentModel = new DocumentModel();
|
|
|
|
self.documents.push(documentModel);
|
|
|
|
return documentModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.removeDocument = function(doc) {
|
|
|
|
var public_id = doc.public_id?doc.public_id():doc;
|
|
|
|
self.documents.remove(function(document) {
|
|
|
|
return document.public_id() == public_id;
|
|
|
|
});
|
|
|
|
}
|
2016-01-21 20:15:30 +01:00
|
|
|
};
|
2016-03-24 23:15:52 +01:00
|
|
|
function DocumentModel(data) {
|
|
|
|
var self = this;
|
|
|
|
self.public_id = ko.observable(0);
|
|
|
|
self.size = ko.observable(0);
|
|
|
|
self.name = ko.observable('');
|
|
|
|
self.type = ko.observable('');
|
|
|
|
self.url = ko.observable('');
|
|
|
|
|
|
|
|
self.update = function(data){
|
|
|
|
ko.mapping.fromJS(data, {}, this);
|
|
|
|
}
|
2016-01-21 20:15:30 +01:00
|
|
|
|
2016-03-24 23:15:52 +01:00
|
|
|
if (data) {
|
|
|
|
self.update(data);
|
2016-05-15 22:16:08 +02:00
|
|
|
}
|
2016-03-24 23:15:52 +01:00
|
|
|
}
|
2016-05-15 22:16:08 +02:00
|
|
|
|
2017-07-20 21:45:10 +02:00
|
|
|
function addDocument(file) {
|
2016-03-24 23:15:52 +01:00
|
|
|
file.index = model.documents().length;
|
|
|
|
model.addDocument({name:file.name, size:file.size, type:file.type});
|
2017-07-20 21:45:10 +02:00
|
|
|
}
|
2016-03-24 23:15:52 +01:00
|
|
|
|
2017-07-20 21:45:10 +02:00
|
|
|
function addedDocument(file, response) {
|
2016-03-24 23:15:52 +01:00
|
|
|
model.documents()[file.index].update(response.document);
|
2017-07-20 21:45:10 +02:00
|
|
|
}
|
2016-05-29 17:42:36 +02:00
|
|
|
|
2017-07-20 21:45:10 +02:00
|
|
|
function deleteDocument(file) {
|
|
|
|
model.removeDocument(file.public_id);
|
|
|
|
}
|
2016-06-05 17:50:41 +02:00
|
|
|
|
2017-07-20 21:45:10 +02:00
|
|
|
function onInvoiceDocumentsChange() {
|
2017-04-28 15:42:19 +02:00
|
|
|
if (isStorageSupported()) {
|
|
|
|
var checked = $('#invoice_documents').is(':checked');
|
|
|
|
localStorage.setItem('last:invoice_documents', checked || '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
</script>
|
2016-01-08 19:01:00 +01:00
|
|
|
|
2016-05-15 22:16:08 +02:00
|
|
|
@stop
|