1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-23 18:01:35 +02:00
invoiceninja/app/views/payments/edit.blade.php

133 lines
3.5 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-05 16:23:24 +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-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') }}
{{ Former::text('payment_date') }}
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 = {};
/*
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;
if (!invoiceMap.hasOwnProperty(client.public_id)) {
invoiceMap[client.public_id] = [];
}
invoiceMap[client.public_id].push(invoice);
clientMap[invoice.public_id] = invoice.client;
}
//clients.sort(compareClient);
$input.append(new Option('', ''));
for (var i=0; i<clients.length; i++) {
var client = clients[i];
$input.append(new Option(client.name, client.public_id));
}
$input.on('change', function(e) {
console.log('client change');
var clientId = $('input[name=client]').val();
var invoiceId = $('input[name=invoice]').val();
if (clientMap.hasOwnProperty(invoiceId) && clientMap[invoiceId].public_id == clientId) {
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('', ''));
var list = clientId ? (invoiceMap.hasOwnProperty(clientId) ? invoiceMap[clientId] : []) : invoices;
for (var i=0; i<list.length; i++) {
var invoice = list[i];
$invoiceCombobox.append(new Option(invoice.invoice_number + ' - ' + invoice.invoice_date + ' - ' + invoice.client.name, invoice.public_id));
}
$('select#invoice').combobox('refresh');
}).trigger('change');
//enableHoverClick($('.client-select input.form-control'), $('input[name=client]'), '{{ URL::to('clients') }}');
$input.combobox();
var $input = $('select#invoice').on('change', function(e) {
$clientCombobox = $('select#client');
var invoiceId = $('input[name=invoice]').val();
if (invoiceId) {
var client = clientMap[invoiceId];
setComboboxValue($('.client-select'), client.public_id, client.name);
//setComboboxValue($('select#client'), client.public_id, client.name);
}
});
//enableHoverClick($('.invoice-select input.form-control'), $('input[name=invoice]'), '{{ URL::to('invoices') }}');
$input.combobox();
$('#payment_date').datepicker({
autoclose: true,
todayHighlight: true
});
});
</script>
@stop