mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Verify that invoice number is unique using JS
This commit is contained in:
parent
f9c8b7eb9b
commit
aa53a96b5d
@ -611,4 +611,15 @@ class InvoiceController extends BaseController
|
||||
|
||||
return View::make('invoices.history', $data);
|
||||
}
|
||||
|
||||
public function checkInvoiceNumber($invoiceNumber)
|
||||
{
|
||||
$count = Invoice::scope()
|
||||
->whereInvoiceNumber($invoiceNumber)
|
||||
->withTrashed()
|
||||
->count();
|
||||
|
||||
return $count ? RESULT_FAILURE : RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -125,7 +125,8 @@ Route::group(['middleware' => 'auth:user'], function() {
|
||||
Route::get('view_archive/{entity_type}/{visible}', 'AccountController@setTrashVisible');
|
||||
Route::get('hide_message', 'HomeController@hideMessage');
|
||||
Route::get('force_inline_pdf', 'UserController@forcePDFJS');
|
||||
Route::get('account/getSearchData', ['as' => 'getSearchData', 'uses' => 'AccountController@getSearchData']);
|
||||
Route::get('account/get_search_data', ['as' => 'get_search_data', 'uses' => 'AccountController@getSearchData']);
|
||||
Route::get('check_invoice_number/{invoice_number}', 'InvoiceController@checkInvoiceNumber');
|
||||
|
||||
Route::get('settings/user_details', 'AccountController@showUserDetails');
|
||||
Route::post('settings/user_details', 'AccountController@saveUserDetails');
|
||||
|
@ -234,7 +234,7 @@
|
||||
|
||||
if (!window.loadedSearchData) {
|
||||
trackEvent('/activity', '/search');
|
||||
var request = $.get('{{ URL::route('getSearchData') }}', function(data) {
|
||||
var request = $.get('{{ URL::route('get_search_data') }}', function(data) {
|
||||
$('#search').typeahead({
|
||||
hint: true,
|
||||
highlight: true,
|
||||
|
@ -162,6 +162,8 @@
|
||||
<span data-bind="visible: !is_recurring()">
|
||||
{!! Former::text('invoice_number')
|
||||
->label(trans("texts.{$entityType}_number_short"))
|
||||
->onchange('checkInvoiceNumber()')
|
||||
->addGroupClass('invoice-number')
|
||||
->data_bind("value: invoice_number, valueUpdate: 'afterkeydown'") !!}
|
||||
</span>
|
||||
@if($account->getTokenGatewayId())
|
||||
@ -1296,6 +1298,11 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
// check invoice number is unique
|
||||
if ($('.invoice-number').hasClass('has-error')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isSaveValid()) {
|
||||
model.showClientForm();
|
||||
return false;
|
||||
|
@ -895,4 +895,25 @@ ko.bindingHandlers.productTypeahead = {
|
||||
}
|
||||
};
|
||||
|
||||
function checkInvoiceNumber() {
|
||||
var url = '{{ url('check_invoice_number') }}/' + $('#invoice_number').val();
|
||||
$.get(url, function(data) {
|
||||
var isValid = data == '{{ RESULT_SUCCESS }}' ? true : false;
|
||||
if (isValid) {
|
||||
$('.invoice-number')
|
||||
.removeClass('has-error')
|
||||
.find('span')
|
||||
.hide();
|
||||
} else {
|
||||
if ($('.invoice-number').hasClass('has-error')) {
|
||||
return;
|
||||
}
|
||||
$('.invoice-number')
|
||||
.addClass('has-error')
|
||||
.find('div')
|
||||
.append('<span class="help-block">{{ trans('validation.unique', ['attribute' => trans('texts.invoice_number')]) }}</span>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user