1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 01:11:34 +02:00
invoiceninja/resources/views/payments/edit.blade.php

381 lines
13 KiB
PHP
Raw Normal View History

2015-03-16 22:45:25 +01:00
@extends('header')
@section('head')
@parent
@include('money_script')
2016-02-03 09:08:28 +01:00
<style type="text/css">
.input-group-addon {
min-width: 40px;
}
</style>
@stop
2015-03-16 22:45:25 +01:00
@section('content')
2016-10-10 10:40:04 +02:00
{!! Former::open($url)
->addClass('col-md-10 col-md-offset-1 warn-on-exit main-form')
->onsubmit('onFormSubmit(event)')
->method($method)
->rules(array(
'client' => 'required',
'invoice' => 'required',
'amount' => 'required',
)) !!}
2015-03-16 22:45:25 +01:00
@if ($payment)
2015-04-06 02:28:43 +02:00
{!! Former::populate($payment) !!}
2017-02-23 19:20:15 +01:00
@else
@if ($account->payment_type_id)
{!! Former::populateField('payment_type_id', $account->payment_type_id) !!}
@endif
2015-03-16 22:45:25 +01:00
@endif
2015-04-20 16:34:23 +02:00
2015-10-28 20:22:07 +01:00
<span style="display:none">
{!! Former::text('public_id') !!}
{!! Former::text('action') !!}
2015-10-28 20:22:07 +01:00
</span>
2016-10-10 10:40:04 +02:00
2015-03-16 22:45:25 +01:00
<div class="row">
2015-04-22 21:21:04 +02:00
<div class="col-md-10 col-md-offset-1">
2015-04-20 16:34:23 +02:00
<div class="panel panel-default">
<div class="panel-body">
2015-03-16 22:45:25 +01:00
@if ($payment)
2017-02-27 09:51:16 +01:00
{!! Former::plaintext()->label('client')->value($payment->client->present()->link) !!}
{!! Former::plaintext()->label('invoice')->value($payment->invoice->present()->link) !!}
{!! Former::plaintext()->label('amount')->value($payment->present()->amount) !!}
@else
2015-03-31 19:42:37 +02:00
{!! Former::select('client')->addOption('', '')->addGroupClass('client-select') !!}
{!! Former::select('invoice')->addOption('', '')->addGroupClass('invoice-select') !!}
2017-11-17 12:56:10 +01:00
{!! Former::text('amount')->append('<span data-bind="html: paymentCurrencyCode"></span>') !!}
2015-11-04 08:48:47 +01:00
@if (isset($paymentTypeId) && $paymentTypeId)
{!! Former::populateField('payment_type_id', $paymentTypeId) !!}
@endif
2015-03-16 22:45:25 +01:00
@endif
2015-06-10 10:34:20 +02:00
@if (!$payment || !$payment->account_gateway_id)
2015-09-01 20:40:30 +02:00
{!! Former::select('payment_type_id')
->addOption('','')
->fromQuery($paymentTypes, 'name', 'id')
->addGroupClass('payment-type-select') !!}
2015-06-10 10:34:20 +02:00
@endif
2015-09-07 11:07:55 +02:00
{!! Former::text('payment_date')
->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT))
->addGroupClass('payment_date')
->append('<i class="glyphicon glyphicon-calendar"></i>') !!}
2015-03-31 19:42:37 +02:00
{!! Former::text('transaction_reference') !!}
2017-05-16 15:47:20 +02:00
{!! Former::textarea('private_notes') !!}
2015-03-16 22:45:25 +01:00
2017-11-17 12:56:10 +01:00
@if (!$payment || ($payment && ! $payment->isExchanged()))
{!! Former::checkbox('convert_currency')
->text(trans('texts.convert_currency'))
->data_bind('checked: convert_currency')
->label(' ')
->value(1) !!}
@endif
<div style="display:none" data-bind="visible: enableExchangeRate">
<br/>
{!! Former::select('exchange_currency_id')->addOption('','')
->label(trans('texts.currency'))
->data_placeholder(Utils::getFromCache($account->getCurrencyId(), 'currencies')->name)
->data_bind('combobox: exchange_currency_id, disable: true')
->fromQuery($currencies, 'name', 'id') !!}
{!! Former::text('exchange_rate')
->data_bind("value: exchange_rate, enable: enableExchangeRate, valueUpdate: 'afterkeydown'") !!}
{!! Former::text('')
->label(trans('texts.amount'))
->data_bind("value: convertedAmount, enable: enableExchangeRate")
->append('<span data-bind="html: exchangeCurrencyCode"></span>') !!}
</div>
@if (!$payment)
{!! Former::checkbox('email_receipt')
->onchange('onEmailReceiptChange()')
->label('&nbsp;')
->text(trans('texts.email_receipt'))
->value(1) !!}
@endif
2015-04-20 16:34:23 +02:00
</div>
</div>
2015-03-16 22:45:25 +01:00
</div>
</div>
2015-04-20 16:34:23 +02:00
2015-03-16 22:45:25 +01:00
<center class="buttons">
2017-06-13 14:42:41 +02:00
{!! Button::normal(trans('texts.cancel'))->appendIcon(Icon::create('remove-circle'))->asLinkTo(HTMLUtils::previousUrl('/payments'))->large() !!}
2016-10-10 10:40:04 +02:00
@if (!$payment || !$payment->is_deleted)
{!! Button::success(trans('texts.save'))->withAttributes(['id' => 'saveButton'])->appendIcon(Icon::create('floppy-disk'))->submit()->large() !!}
2016-10-10 10:40:04 +02:00
@endif
@if ($payment)
{!! DropdownButton::normal(trans('texts.more_actions'))
->withContents($actions)
->large()
->dropup() !!}
@endif
2015-03-16 22:45:25 +01:00
</center>
@include('partials/refund_payment')
2015-03-31 19:42:37 +02:00
{!! Former::close() !!}
2015-03-16 22:45:25 +01:00
<script type="text/javascript">
2017-05-08 21:10:39 +02:00
var invoices = {!! $invoices !!};
var clients = {!! $clients !!};
2015-03-16 22:45:25 +01:00
2017-11-17 12:56:10 +01:00
var clientMap = {};
var invoiceMap = {};
var invoicesForClientMap = {};
for (var i=0; i<clients.length; i++) {
var client = clients[i];
clientMap[client.public_id] = client;
}
for (var i=0; i<invoices.length; i++) {
var invoice = invoices[i];
var client = invoice.client;
if (!invoicesForClientMap.hasOwnProperty(client.public_id)) {
invoicesForClientMap[client.public_id] = [];
}
invoicesForClientMap[client.public_id].push(invoice);
invoiceMap[invoice.public_id] = invoice;
}
2015-03-16 22:45:25 +01:00
$(function() {
2017-11-18 19:12:52 +01:00
@if (Input::old('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({!! $payment !!});
@endif
ko.applyBindings(model);
$('#amount').change(function() {
var amount = $('#amount').val();
model.amount(NINJA.parseFloat(amount));
})
2015-03-16 22:45:25 +01:00
@if ($payment)
$('#payment_date').datepicker('update', '{{ $payment->payment_date }}')
@if ($payment->payment_type_id != PAYMENT_TYPE_CREDIT)
$("#payment_type_id option[value='{{ PAYMENT_TYPE_CREDIT }}']").remove();
@endif
2015-03-16 22:45:25 +01:00
@else
$('#payment_date').datepicker('update', new Date());
populateInvoiceComboboxes({{ $clientPublicId }}, {{ $invoicePublicId }});
@endif
2016-10-10 10:40:04 +02:00
$('#payment_type_id').combobox();
2015-03-16 22:45:25 +01:00
2015-05-10 21:02:35 +02:00
@if (!$payment && !$clientPublicId)
2015-05-09 20:25:16 +02:00
$('.client-select input.form-control').focus();
2015-05-10 21:02:35 +02:00
@elseif (!$payment && !$invoicePublicId)
2015-05-09 20:25:16 +02:00
$('.invoice-select input.form-control').focus();
@elseif (!$payment)
$('#amount').focus();
@endif
2015-09-07 11:07:55 +02:00
$('.payment_date .input-group-addon').click(function() {
toggleDatePicker('payment_date');
});
if (isStorageSupported()) {
if (localStorage.getItem('last:send_email_receipt')) {
$('#email_receipt').prop('checked', true);
}
}
2015-03-16 22:45:25 +01:00
});
function onFormSubmit(event) {
$('#saveButton').attr('disabled', true);
}
function submitAction(action) {
$('#action').val(action);
$('.main-form').submit();
}
function submitForm_payment(action) {
submitAction(action);
}
function onDeleteClick() {
sweetConfirm(function() {
submitAction('delete');
});
}
function onEmailReceiptChange() {
if (! isStorageSupported()) {
return;
}
var checked = $('#email_receipt').is(':checked');
localStorage.setItem('last:send_email_receipt', checked ? true : '');
}
2017-11-17 12:56:10 +01:00
var ViewModel = function(data) {
var self = this;
self.client_id = ko.observable();
self.exchange_currency_id = ko.observable();
self.amount = ko.observable();
self.exchange_rate = ko.observable(1);
self.convert_currency = ko.observable({{ ($payment && $payment->isExchanged()) ? 'true' : 'false' }});
if (data) {
ko.mapping.fromJS(data, self.mapping, this);
self.exchange_rate(roundSignificant(self.exchange_rate()));
}
self.account_currency_id = ko.observable({{ $account->getCurrencyId() }});
self.convertedAmount = ko.computed({
read: function () {
return roundToTwo(self.amount() * self.exchange_rate()).toFixed(2);
},
write: function(value) {
var amount = NINJA.parseFloat(value) / self.amount();
self.exchange_rate(roundSignificant(amount));
}
}, self);
self.getCurrency = function(currencyId) {
return currencyMap[currencyId || self.account_currency_id()];
};
self.exchangeCurrencyCode = ko.computed(function() {
return self.getCurrency(self.exchange_currency_id()).code;
});
self.paymentCurrencyCode = ko.computed(function() {
var client = clientMap[self.client_id()];
if (client && client.currency_id) {
var currencyId = client.currency_id;
} else {
var currencyId = self.account_currency_id();
}
return self.getCurrency(currencyId).code;
});
self.enableExchangeRate = ko.computed(function() {
if (self.convert_currency()) {
return true;
}
/*
var expenseCurrencyId = self.expense_currency_id() || self.account_currency_id();
var invoiceCurrencyId = self.invoice_currency_id() || self.account_currency_id();
return expenseCurrencyId != invoiceCurrencyId
|| invoiceCurrencyId != self.account_currency_id()
|| expenseCurrencyId != self.account_currency_id();
*/
})
};
function populateInvoiceComboboxes(clientId, invoiceId) {
var $clientSelect = $('select#client');
$clientSelect.append(new Option('', ''));
for (var i=0; i<clients.length; i++) {
var client = clients[i];
var clientName = getClientDisplayName(client);
if (!clientName) {
continue;
}
$clientSelect.append(new Option(clientName, client.public_id));
}
if (clientId) {
$clientSelect.val(clientId);
}
$clientSelect.combobox({highlighter: comboboxHighlighter});
$clientSelect.on('change', function(e) {
var clientId = $('input[name=client]').val();
var invoiceId = $('input[name=invoice]').val();
var invoice = invoiceMap[invoiceId];
if (invoice && invoice.client.public_id == clientId) {
e.preventDefault();
return;
}
setComboboxValue($('.invoice-select'), '', '');
$invoiceCombobox = $('select#invoice');
$invoiceCombobox.find('option').remove().end().combobox('refresh');
$invoiceCombobox.append(new Option('', ''));
var list = clientId ? (invoicesForClientMap.hasOwnProperty(clientId) ? invoicesForClientMap[clientId] : []) : invoices;
for (var i=0; i<list.length; i++) {
var invoice = list[i];
var client = clientMap[invoice.client.public_id];
if (!client || !getClientDisplayName(client)) continue; // client is deleted/archived
$invoiceCombobox.append(new Option(invoice.invoice_number + ' - ' + invoice.invoice_status.name + ' - ' +
getClientDisplayName(client) + ' - ' + formatMoneyInvoice(invoice.amount, invoice) + ' | ' +
formatMoneyInvoice(invoice.balance, invoice), invoice.public_id));
}
$('select#invoice').combobox('refresh');
if (window.model) {
model.client_id(clientId);
}
});
2017-11-18 19:12:52 +01:00
if (clientId) {
$clientSelect.trigger('change');
}
2017-11-17 12:56:10 +01:00
var $invoiceSelect = $('select#invoice').on('change', function(e) {
$clientCombobox = $('select#client');
var invoiceId = $('input[name=invoice]').val();
if (invoiceId) {
var invoice = invoiceMap[invoiceId];
var client = clientMap[invoice.client.public_id];
invoice.client = client;
setComboboxValue($('.client-select'), client.public_id, getClientDisplayName(client));
if (!parseFloat($('#amount').val())) {
var amount = parseFloat(invoice.balance);
$('#amount').val(amount.toFixed(2));
model.amount(amount);
}
}
2017-11-18 19:12:52 +01:00
model.client_id(client ? client.public_id : 0);
2017-11-17 12:56:10 +01:00
});
$invoiceSelect.combobox({highlighter: comboboxHighlighter});
if (invoiceId) {
var invoice = invoiceMap[invoiceId];
var client = clientMap[invoice.client.public_id];
invoice.client = client;
setComboboxValue($('.invoice-select'), invoice.public_id, (invoice.invoice_number + ' - ' +
invoice.invoice_status.name + ' - ' + getClientDisplayName(client) + ' - ' +
formatMoneyInvoice(invoice.amount, invoice) + ' | ' + formatMoneyInvoice(invoice.balance, invoice)));
$invoiceSelect.trigger('change');
} else if (clientId) {
var client = clientMap[clientId];
setComboboxValue($('.client-select'), client.public_id, getClientDisplayName(client));
$clientSelect.trigger('change');
} else {
$clientSelect.trigger('change');
}
}
2015-03-16 22:45:25 +01:00
</script>
2016-10-10 10:40:04 +02:00
@stop