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-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
|
|
|
|
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
|
|
|
|
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'))
|
|
|
|
->data_placeholder(Utils::getFromCache($account->getCurrencyId(), 'currencies')->name)
|
|
|
|
->fromQuery($currencies, 'name', 'id') !!}
|
|
|
|
|
|
|
|
{!! 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
|
|
|
{!! Former::select('client_id')
|
|
|
|
->addOption('', '')
|
|
|
|
->label(trans('texts.client'))
|
|
|
|
->data_bind('combobox: client_id')
|
|
|
|
->addGroupClass('client-select') !!}
|
|
|
|
|
2016-02-17 14:52:16 +01:00
|
|
|
@if (!$expense || ($expense && !$expense->invoice_id && !$expense->client_id))
|
2016-01-21 21:36:49 +01:00
|
|
|
{!! Former::checkbox('should_be_invoiced')
|
|
|
|
->text(trans('texts.should_be_invoiced'))
|
|
|
|
->data_bind('checked: should_be_invoiced() || client_id(), enable: !client_id()')
|
2016-02-17 12:06:03 +01:00
|
|
|
->label(' ') !!}
|
2016-01-21 21:36:49 +01:00
|
|
|
@endif
|
2016-01-21 20:15:30 +01:00
|
|
|
|
2016-02-17 12:06:03 +01:00
|
|
|
@if (!$expense || ($expense && ! $expense->isExchanged()))
|
|
|
|
{!! Former::checkbox('convert_currency')
|
|
|
|
->text(trans('texts.convert_currency'))
|
|
|
|
->data_bind('checked: convert_currency')
|
|
|
|
->label(' ') !!}
|
|
|
|
@endif
|
|
|
|
<br/>
|
|
|
|
|
|
|
|
<div style="display:none" data-bind="visible: enableExchangeRate">
|
|
|
|
<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)
|
|
|
|
->data_bind('combobox: invoice_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: 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>') !!}
|
|
|
|
</div>
|
2016-01-08 19:01:00 +01:00
|
|
|
</div>
|
2016-01-20 23:09:10 +01:00
|
|
|
<div class="col-md-6">
|
|
|
|
|
2016-02-17 12:06:03 +01:00
|
|
|
{!! Former::textarea('public_notes')->rows(8) !!}
|
|
|
|
{!! Former::textarea('private_notes')->rows(8) !!}
|
|
|
|
|
2016-01-20 23:09:10 +01:00
|
|
|
</div>
|
2016-01-08 19:01:00 +01:00
|
|
|
</div>
|
2016-03-24 23:15:52 +01:00
|
|
|
@if ($account->isPro())
|
|
|
|
<div clas="row">
|
|
|
|
<div class="col-md-2 col-sm-4"><div class="control-label" style="margin-bottom:10px;">{{trans('texts.expense_documents')}}</div></div>
|
|
|
|
<div class="col-md-12 col-sm-8">
|
|
|
|
<div role="tabpanel" class="tab-pane" id="attached-documents" style="position:relative;z-index:9">
|
|
|
|
<div id="document-upload" class="dropzone">
|
|
|
|
<div class="fallback">
|
|
|
|
<input name="documents[]" type="file" multiple />
|
|
|
|
</div>
|
|
|
|
<div data-bind="foreach: documents">
|
|
|
|
<div class="fallback-doc">
|
|
|
|
<a href="#" class="fallback-doc-remove" data-bind="click: $parent.removeDocument"><i class="fa fa-close"></i></a>
|
|
|
|
<span data-bind="text:name"></span>
|
|
|
|
<input type="hidden" name="document_ids[]" data-bind="value: public_id"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
@endif
|
2016-01-08 19:01:00 +01:00
|
|
|
</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-03-24 23:15:52 +01:00
|
|
|
Dropzone.autoDiscover = false;
|
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) {
|
2016-02-01 23:07:09 +01:00
|
|
|
model.invoice_currency_id(client.currency_id);
|
2016-01-21 20:15:30 +01:00
|
|
|
}
|
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();
|
|
|
|
|
2016-02-18 11:02:30 +01:00
|
|
|
$('#expense_date').datepicker('update', '{{ $expense ? $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];
|
|
|
|
$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-03-24 23:15:52 +01:00
|
|
|
|
|
|
|
@if (Auth::user()->account->isPro())
|
|
|
|
$('.main-form').submit(function(){
|
|
|
|
if($('#document-upload .fallback input').val())$(this).attr('enctype', 'multipart/form-data')
|
|
|
|
else $(this).removeAttr('enctype')
|
|
|
|
})
|
|
|
|
|
|
|
|
// Initialize document upload
|
|
|
|
dropzone = new Dropzone('#document-upload', {
|
|
|
|
url:{!! json_encode(url('document')) !!},
|
|
|
|
params:{
|
|
|
|
_token:"{{ Session::getToken() }}"
|
|
|
|
},
|
|
|
|
acceptedFiles:{!! json_encode(implode(',',\App\Models\Document::$allowedMimes)) !!},
|
|
|
|
addRemoveLinks:true,
|
2016-03-24 23:45:00 +01:00
|
|
|
@foreach(trans('texts.dropzone') as $key=>$text)
|
|
|
|
"dict{{strval($key)}}":"{{strval($text)}}",
|
|
|
|
@endforeach
|
2016-03-24 23:15:52 +01:00
|
|
|
maxFileSize:{{floatval(MAX_DOCUMENT_SIZE/1000)}},
|
|
|
|
});
|
|
|
|
if(dropzone instanceof Dropzone){
|
|
|
|
dropzone.on("addedfile",handleDocumentAdded);
|
|
|
|
dropzone.on("removedfile",handleDocumentRemoved);
|
|
|
|
dropzone.on("success",handleDocumentUploaded);
|
|
|
|
for (var i=0; i<model.documents().length; i++) {
|
|
|
|
var document = model.documents()[i];
|
|
|
|
var mockFile = {
|
|
|
|
name:document.name(),
|
|
|
|
size:document.size(),
|
|
|
|
type:document.type(),
|
|
|
|
public_id:document.public_id(),
|
|
|
|
status:Dropzone.SUCCESS,
|
|
|
|
accepted:true,
|
|
|
|
url:document.preview_url()||document.url(),
|
|
|
|
mock:true,
|
|
|
|
index:i
|
|
|
|
};
|
|
|
|
|
|
|
|
dropzone.emit('addedfile', mockFile);
|
|
|
|
dropzone.emit('complete', mockFile);
|
|
|
|
if(document.preview_url()){
|
|
|
|
dropzone.emit('thumbnail', mockFile, document.preview_url()||document.url());
|
|
|
|
}
|
|
|
|
else if(document.type()=='jpeg' || document.type()=='png' || document.type()=='svg'){
|
|
|
|
dropzone.emit('thumbnail', mockFile, document.url());
|
|
|
|
}
|
|
|
|
dropzone.files.push(mockFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@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-02-17 12:06:03 +01:00
|
|
|
self.convert_currency = ko.observable(false);
|
2016-01-21 20:15:30 +01:00
|
|
|
|
2016-03-24 23:15:52 +01:00
|
|
|
self.mapping = {
|
|
|
|
'documents': {
|
|
|
|
create: function(options) {
|
|
|
|
return new DocumentModel(options.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-01-27 19:31:08 +01:00
|
|
|
self.account_currency_id = ko.observable({{ $account->getCurrencyId() }});
|
|
|
|
self.client_id = ko.observable({{ $clientPublicId }});
|
|
|
|
self.vendor_id = ko.observable({{ $vendorPublicId }});
|
|
|
|
|
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) {
|
2016-01-31 16:34:11 +01:00
|
|
|
self.amount(roundToTwo(value / self.exchange_rate()));
|
2016-01-21 21:36:49 +01:00
|
|
|
}
|
|
|
|
}, self);
|
|
|
|
|
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() {
|
2016-02-17 12:06:03 +01:00
|
|
|
if (self.convert_currency()) {
|
|
|
|
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-02-17 12:06:03 +01:00
|
|
|
return expenseCurrencyId != invoiceCurrencyId
|
|
|
|
|| invoiceCurrencyId != self.account_currency_id()
|
|
|
|
|| expenseCurrencyId != self.account_currency_id();
|
2016-01-21 20:15:30 +01: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-04-19 04:35:18 +02:00
|
|
|
@if (Auth::user()->account->hasFeature(FEATURE_DOCUMENTS))
|
2016-03-24 23:15:52 +01:00
|
|
|
function handleDocumentAdded(file){
|
|
|
|
if(file.mock)return;
|
|
|
|
file.index = model.documents().length;
|
|
|
|
model.addDocument({name:file.name, size:file.size, type:file.type});
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleDocumentRemoved(file){
|
|
|
|
model.removeDocument(file.public_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleDocumentUploaded(file, response){
|
|
|
|
file.public_id = response.document.public_id
|
|
|
|
model.documents()[file.index].update(response.document);
|
|
|
|
|
|
|
|
if(response.document.preview_url){
|
|
|
|
dropzone.emit('thumbnail', file, response.document.preview_url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@endif
|
2016-01-21 20:15:30 +01:00
|
|
|
</script>
|
2016-01-08 19:01:00 +01:00
|
|
|
|
|
|
|
@stop
|