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',
|
|
|
|
'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') }}
|
2013-12-29 18:40:11 +01:00
|
|
|
{{ Former::select('currency_id')->addOption('','')->label('Currency')
|
|
|
|
->fromQuery($currencies, 'name', 'id')->select(Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY)) }}
|
2013-12-05 16:23:24 +01:00
|
|
|
{{ Former::text('amount') }}
|
2013-12-25 22:34:42 +01:00
|
|
|
{{ Former::text('payment_date')->data_date_format(DEFAULT_DATE_PICKER_FORMAT) }}
|
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') }} |
|
|
|
|
{{ 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));
|
|
|
|
}
|
|
|
|
|
2013-12-09 10:38:49 +01:00
|
|
|
@if ($client)
|
|
|
|
$('select#client').val({{ $client->public_id }});
|
|
|
|
@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();
|
|
|
|
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];
|
2013-12-29 18:40:11 +01:00
|
|
|
$invoiceCombobox.append(new Option(invoice.invoice_number + ' - ' + invoice.client.name, 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) {
|
|
|
|
var client = clientMap[invoiceId];
|
2013-12-08 14:32:49 +01:00
|
|
|
setComboboxValue($('.client-select'), client.public_id, client.name);
|
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,
|
|
|
|
todayHighlight: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
@stop
|