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

151 lines
4.1 KiB
PHP
Raw Normal View History

2013-12-04 17:20:14 +01:00
@extends('header')
@section('onReady')
$('input#name').focus();
@stop
@section('content')
{{ Former::open($url)->addClass('col-md-10 col-md-offset-1 main_form')->method($method)->rules(array(
2013-12-08 14:32:49 +01:00
'client' => 'required',
2013-12-30 21:17:45 +01:00
'invoice' => 'required',
2013-12-08 14:32:49 +01:00
'amount' => 'required',
2013-12-04 17:20:14 +01:00
)); }}
@if ($payment)
2013-12-05 16:23:24 +01:00
{{-- Former::populate($payment) --}}
2013-12-30 21:17:45 +01:00
@else
2014-01-01 00:50:13 +01:00
{{ Former::populateField('payment_date', Utils::today()) }}
2013-12-04 17:20:14 +01:00
@endif
<div class="row">
2013-12-05 16:23:24 +01:00
<div class="col-md-8">
2013-12-04 17:20:14 +01:00
@if ($payment)
{{ Former::legend('Edit Payment') }}
@else
{{ Former::legend('New Payment') }}
@endif
2013-12-05 16:23:24 +01:00
{{ Former::select('client')->addOption('', '')->addGroupClass('client-select') }}
{{ Former::select('invoice')->addOption('', '')->addGroupClass('invoice-select') }}
{{ Former::text('amount') }}
2014-01-01 00:50:13 +01:00
{{ Former::text('payment_date')->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT)) }}
2013-12-30 21:17:45 +01:00
{{ Former::select('currency_id')->addOption('','')->label('Currency')
->fromQuery($currencies, 'name', 'id')->select(Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY)) }}
2013-12-04 17:20:14 +01:00
</div>
<div class="col-md-6">
</div>
</div>
<center style="margin-top:16px">
{{ Button::lg_primary_submit('Save') }} &nbsp;|&nbsp;
{{ link_to('payments/' . ($payment ? $payment->public_id : ''), 'Cancel') }}
</center>
{{ Former::close() }}
2013-12-05 16:23:24 +01:00
<script type="text/javascript">
var invoices = {{ $invoices }};
var clients = {{ $clients }};
var clientMap = {};
var invoiceMap = {};
2013-12-30 21:17:45 +01:00
var invoicesForClientMap = {};
2013-12-05 16:23:24 +01:00
/*
function compareClient(a,b) {
if (a.name < b.name)
return -1;
if (a.name> b.name)
return 1;
return 0;
}
*/
$(function() {
var $input = $('select#client');
for (var i=0; i<invoices.length; i++) {
var invoice = invoices[i];
var client = invoice.client;
2013-12-30 21:17:45 +01:00
if (!invoicesForClientMap.hasOwnProperty(client.public_id)) {
invoicesForClientMap[client.public_id] = [];
2013-12-05 16:23:24 +01:00
}
2013-12-30 21:17:45 +01:00
invoicesForClientMap[client.public_id].push(invoice);
invoiceMap[invoice.public_id] = invoice;
//clientMap[invoice.public_id] = invoice.client;
}
for (var i=0; i<clients.length; i++) {
var client = clients[i];
clientMap[client.public_id] = client;
2013-12-05 16:23:24 +01:00
}
//clients.sort(compareClient);
$input.append(new Option('', ''));
for (var i=0; i<clients.length; i++) {
var client = clients[i];
2013-12-30 21:17:45 +01:00
$input.append(new Option(getClientDisplayName(client), client.public_id));
2013-12-05 16:23:24 +01:00
}
2013-12-30 21:17:45 +01:00
@if ($clientPublicId)
$('select#client').val({{ $clientPublicId }});
2013-12-09 10:38:49 +01:00
@endif
$input.combobox();
2013-12-05 16:23:24 +01:00
$input.on('change', function(e) {
console.log('client change');
var clientId = $('input[name=client]').val();
var invoiceId = $('input[name=invoice]').val();
2013-12-30 21:17:45 +01:00
var invoice = invoiceMap[invoiceId];
if (invoice && invoice.client.public_id == clientId) {
2013-12-05 16:23:24 +01:00
console.log('values the same:' + $('select#client').prop('selected'))
e.preventDefault();
return;
}
setComboboxValue($('.invoice-select'), '', '');
$invoiceCombobox = $('select#invoice');
$invoiceCombobox.find('option').remove().end().combobox('refresh');
$invoiceCombobox.append(new Option('', ''));
2013-12-30 21:17:45 +01:00
var list = clientId ? (invoicesForClientMap.hasOwnProperty(clientId) ? invoicesForClientMap[clientId] : []) : invoices;
2013-12-05 16:23:24 +01:00
for (var i=0; i<list.length; i++) {
var invoice = list[i];
2013-12-30 21:17:45 +01:00
var client = clientMap[invoice.client.public_id];
2014-01-02 00:12:33 +01:00
$invoiceCombobox.append(new Option(invoice.invoice_number + ' - ' + getClientDisplayName(client) + ' - ' + formatMoney(invoice.balance, invoice.currency_id), invoice.public_id));
2013-12-05 16:23:24 +01:00
}
$('select#invoice').combobox('refresh');
}).trigger('change');
var $input = $('select#invoice').on('change', function(e) {
$clientCombobox = $('select#client');
var invoiceId = $('input[name=invoice]').val();
if (invoiceId) {
2013-12-30 21:17:45 +01:00
var invoice = invoiceMap[invoiceId];
var client = clientMap[invoice.client.public_id];
setComboboxValue($('.client-select'), client.public_id, getClientDisplayName(client));
2013-12-05 16:23:24 +01:00
}
});
$input.combobox();
2013-12-29 18:40:11 +01:00
$('#currency_id').combobox();
2013-12-05 16:23:24 +01:00
$('#payment_date').datepicker({
autoclose: true,
2014-01-01 00:50:13 +01:00
todayHighlight: true,
keyboardNavigation: false
2013-12-05 16:23:24 +01:00
});
});
</script>
@stop