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-01-20 23:09:10 +01:00
|
|
|
@stop
|
|
|
|
|
2016-01-08 19:01:00 +01:00
|
|
|
@section('content')
|
|
|
|
|
2016-01-21 23:29:10 +01:00
|
|
|
{!! Former::open($url)->addClass('warn-on-exit main-form')->method($method) !!}
|
|
|
|
<div style="display:none">
|
|
|
|
{!! Former::text('action') !!}
|
|
|
|
</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-01-08 19:01:00 +01:00
|
|
|
{!! Former::hidden('public_id') !!}
|
|
|
|
@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-01-21 20:15:30 +01:00
|
|
|
{!! Former::select('vendor_id')->addOption('', '')
|
|
|
|
->data_bind('combobox: vendor_id')
|
|
|
|
->label(trans('texts.vendor'))
|
2016-01-20 23:09:10 +01:00
|
|
|
->addGroupClass('vendor-select') !!}
|
2016-01-21 20:15:30 +01:00
|
|
|
|
|
|
|
{!! Former::text('amount')
|
|
|
|
->label(trans('texts.amount'))
|
2016-01-21 21:36:49 +01:00
|
|
|
->data_bind("value: amount, valueUpdate: 'afterkeydown'")
|
2016-01-21 20:15:30 +01:00
|
|
|
->addGroupClass('amount')
|
|
|
|
->append($account->present()->currencyCode) !!}
|
|
|
|
|
2016-01-20 23:09:10 +01:00
|
|
|
{!! Former::text('expense_date')
|
|
|
|
->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))
|
2016-01-21 20:15:30 +01:00
|
|
|
->addGroupClass('expense_date')
|
|
|
|
->label(trans('texts.date'))
|
2016-01-20 23:09:10 +01:00
|
|
|
->append('<i class="glyphicon glyphicon-calendar"></i>') !!}
|
2016-01-21 20:15:30 +01:00
|
|
|
|
|
|
|
{!! Former::select('client_id')
|
|
|
|
->addOption('', '')
|
|
|
|
->label(trans('texts.client'))
|
|
|
|
->data_bind('combobox: client_id')
|
|
|
|
->addGroupClass('client-select') !!}
|
|
|
|
|
2016-01-21 21:36:49 +01:00
|
|
|
@if (!$expense || ($expense && !$expense->invoice_id))
|
|
|
|
{!! Former::checkbox('should_be_invoiced')
|
|
|
|
->text(trans('texts.should_be_invoiced'))
|
|
|
|
->data_bind('checked: should_be_invoiced() || client_id(), enable: !client_id()')
|
|
|
|
->label(' ') !!}<br/>
|
|
|
|
@endif
|
2016-01-21 20:15:30 +01:00
|
|
|
|
|
|
|
<span style="display:none" data-bind="visible: !client_id()">
|
|
|
|
{!! Former::select('currency_id')->addOption('','')
|
|
|
|
->data_bind('combobox: currency_id, disable: true')
|
|
|
|
->fromQuery($currencies, 'name', 'id') !!}
|
|
|
|
</span>
|
|
|
|
<span style="display:none;" data-bind="visible: client_id">
|
|
|
|
{!! Former::plaintext('test')
|
|
|
|
->value('<span data-bind="html: currencyName"></span>')
|
|
|
|
->style('min-height:46px')
|
|
|
|
->label(trans('texts.currency_id')) !!}
|
|
|
|
</span>
|
|
|
|
|
|
|
|
{!! Former::text('exchange_rate')
|
2016-01-21 21:36:49 +01:00
|
|
|
->data_bind("value: exchange_rate, enable: enableExchangeRate, valueUpdate: 'afterkeydown'") !!}
|
2016-01-21 20:15:30 +01:00
|
|
|
|
2016-01-23 19:36:11 +01:00
|
|
|
{!! Former::text('invoice_amount')
|
2016-01-21 20:15:30 +01:00
|
|
|
->addGroupClass('converted-amount')
|
2016-01-21 21:36:49 +01:00
|
|
|
->data_bind("value: convertedAmount, enable: enableExchangeRate")
|
2016-01-21 20:15:30 +01:00
|
|
|
->append('<span data-bind="html: currencyCode"></span>') !!}
|
|
|
|
|
2016-01-08 19:01:00 +01:00
|
|
|
</div>
|
2016-01-20 23:09:10 +01:00
|
|
|
<div class="col-md-6">
|
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
{!! Former::textarea('public_notes')->rows(9) !!}
|
|
|
|
{!! Former::textarea('private_notes')->rows(9) !!}
|
2016-01-20 23:09:10 +01:00
|
|
|
</div>
|
2016-01-08 19:01:00 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<center class="buttons">
|
2016-01-20 23:09:10 +01:00
|
|
|
{!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(URL::to('/expenses'))->appendIcon(Icon::create('remove-circle')) !!}
|
2016-01-08 19:01:00 +01:00
|
|
|
{!! Button::success(trans('texts.save'))->submit()->large()->appendIcon(Icon::create('floppy-disk')) !!}
|
2016-01-21 23:29:10 +01:00
|
|
|
@if ($expense)
|
|
|
|
{!! DropdownButton::normal(trans('texts.more_actions'))
|
|
|
|
->withContents($actions)
|
|
|
|
->large()
|
|
|
|
->dropup() !!}
|
|
|
|
@endif
|
2016-01-08 19:01:00 +01:00
|
|
|
</center>
|
|
|
|
|
|
|
|
{!! Former::close() !!}
|
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
<script type="text/javascript">
|
2016-01-09 06:24:43 +01:00
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
var vendors = {!! $vendors !!};
|
|
|
|
var clients = {!! $clients !!};
|
2016-01-09 06:24:43 +01:00
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
var clientMap = {};
|
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-01-21 20:15:30 +01:00
|
|
|
function onClientChange() {
|
|
|
|
var clientId = $('select#client_id').val();
|
|
|
|
var client = clientMap[clientId];
|
|
|
|
if (client) {
|
|
|
|
model.currency_id(client.currency_id);
|
|
|
|
}
|
2016-01-09 06:24:43 +01:00
|
|
|
}
|
|
|
|
|
2016-01-21 23:29:10 +01:00
|
|
|
function submitAction(action) {
|
|
|
|
$('#action').val(action);
|
|
|
|
$('.main-form').submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDeleteClick() {
|
|
|
|
if (confirm('{!! trans("texts.are_you_sure") !!}')) {
|
|
|
|
submitAction('delete');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
$(function() {
|
|
|
|
|
|
|
|
var $vendorSelect = $('select#vendor_id');
|
|
|
|
for (var i = 0; i < vendors.length; i++) {
|
|
|
|
var vendor = vendors[i];
|
|
|
|
$vendorSelect.append(new Option(getClientDisplayName(vendor), vendor.public_id));
|
|
|
|
}
|
|
|
|
$vendorSelect.combobox();
|
|
|
|
|
|
|
|
$('#expense_date').datepicker('update', new Date());
|
|
|
|
|
|
|
|
$('.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];
|
|
|
|
$clientSelect.append(new Option(getClientDisplayName(client), client.public_id));
|
|
|
|
}
|
|
|
|
$clientSelect.combobox().change(function() {
|
|
|
|
onClientChange();
|
|
|
|
});
|
|
|
|
|
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 !!});
|
|
|
|
|
|
|
|
ko.applyBindings(model);
|
|
|
|
@endif
|
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-01-21 21:36:49 +01:00
|
|
|
var ViewModel = function(data) {
|
2016-01-21 20:15:30 +01:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.client_id = ko.observable({{ $clientPublicId }});
|
|
|
|
self.vendor_id = ko.observable({{ $vendorPublicId }});
|
2016-01-21 21:36:49 +01:00
|
|
|
self.currency_id = ko.observable();
|
|
|
|
self.amount = ko.observable();
|
|
|
|
self.exchange_rate = ko.observable(1);
|
|
|
|
self.should_be_invoiced = ko.observable();
|
2016-01-21 20:15:30 +01:00
|
|
|
self.account_currency_id = ko.observable({{ $account->getCurrencyId() }});
|
|
|
|
|
2016-01-21 21:36:49 +01:00
|
|
|
if (data) {
|
|
|
|
ko.mapping.fromJS(data, {}, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.convertedAmount = ko.computed({
|
|
|
|
read: function () {
|
|
|
|
return roundToTwo(self.amount() * self.exchange_rate()).toFixed(2);
|
|
|
|
},
|
|
|
|
write: function(value) {
|
|
|
|
self.exchange_rate(roundToFour(value / self.amount()));
|
|
|
|
}
|
|
|
|
}, self);
|
|
|
|
|
2016-01-21 20:15:30 +01:00
|
|
|
self.currencyCode = ko.computed(function() {
|
|
|
|
var currencyId = self.currency_id() || self.account_currency_id();
|
|
|
|
var currency = currencyMap[currencyId];
|
|
|
|
return currency.code;
|
|
|
|
});
|
|
|
|
|
|
|
|
self.currencyName = ko.computed(function() {
|
|
|
|
var currencyId = self.currency_id() || self.account_currency_id();
|
|
|
|
var currency = currencyMap[currencyId];
|
2016-01-21 21:36:49 +01:00
|
|
|
console.log(currencyId);
|
2016-01-21 20:15:30 +01:00
|
|
|
return currency.name;
|
|
|
|
});
|
|
|
|
|
|
|
|
self.enableExchangeRate = ko.computed(function() {
|
|
|
|
if (!self.currency_id()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return self.currency_id() != self.account_currency_id();
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
</script>
|
2016-01-08 19:01:00 +01:00
|
|
|
|
|
|
|
@stop
|