Standardize partial/deposit error

This commit is contained in:
Hillel Coren 2016-09-21 17:07:01 +03:00
parent 7ae01f8f42
commit 8a8a80c414
2 changed files with 28 additions and 20 deletions

View File

@ -306,9 +306,6 @@ class InvoiceRepository extends BaseRepository
if (isset($data['is_amount_discount'])) { if (isset($data['is_amount_discount'])) {
$invoice->is_amount_discount = $data['is_amount_discount'] ? true : false; $invoice->is_amount_discount = $data['is_amount_discount'] ? true : false;
} }
if (isset($data['partial'])) {
$invoice->partial = round(Utils::parseFloat($data['partial']), 2);
}
if (isset($data['invoice_date_sql'])) { if (isset($data['invoice_date_sql'])) {
$invoice->invoice_date = $data['invoice_date_sql']; $invoice->invoice_date = $data['invoice_date_sql'];
} elseif (isset($data['invoice_date'])) { } elseif (isset($data['invoice_date'])) {
@ -477,6 +474,10 @@ class InvoiceRepository extends BaseRepository
$invoice->balance = $total; $invoice->balance = $total;
} }
if (isset($data['partial'])) {
$invoice->partial = min(round(Utils::parseFloat($data['partial']), 2), $invoice->balance);
}
$invoice->amount = $total; $invoice->amount = $total;
$invoice->save(); $invoice->save();

View File

@ -13,11 +13,6 @@
<link href="{{ asset('css/lightbox.css') }}" rel="stylesheet" type="text/css"/> <link href="{{ asset('css/lightbox.css') }}" rel="stylesheet" type="text/css"/>
<style type="text/css"> <style type="text/css">
/* the value is auto set so we're removing the bold formatting */
label.control-label[for=invoice_number] {
font-weight: normal !important;
}
select.tax-select { select.tax-select {
width: 50%; width: 50%;
float: left; float: left;
@ -55,6 +50,7 @@
->rules(array( ->rules(array(
'client' => 'required', 'client' => 'required',
'invoice_number' => 'required', 'invoice_number' => 'required',
'invoice_date' => 'required',
'product_key' => 'max:255' 'product_key' => 'max:255'
)) !!} )) !!}
@ -71,7 +67,7 @@
@if ($invoice->id || $data) @if ($invoice->id || $data)
<div class="form-group"> <div class="form-group">
<label for="client" class="control-label col-lg-4 col-sm-4">{{ trans('texts.client') }}</label> <label for="client" class="control-label col-lg-4 col-sm-4"><b>{{ trans('texts.client') }}</b></label>
<div class="col-lg-8 col-sm-8"> <div class="col-lg-8 col-sm-8">
<h4> <h4>
<span data-bind="text: getClientDisplayName(ko.toJS(client()))"></span> <span data-bind="text: getClientDisplayName(ko.toJS(client()))"></span>
@ -138,8 +134,8 @@
{!! Former::text('due_date')->data_bind("datePicker: due_date, valueUpdate: 'afterkeydown'")->label(trans("texts.{$entityType}_due_date")) {!! Former::text('due_date')->data_bind("datePicker: due_date, valueUpdate: 'afterkeydown'")->label(trans("texts.{$entityType}_due_date"))
->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))->appendIcon('calendar')->addGroupClass('due_date') !!} ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT, DEFAULT_DATE_PICKER_FORMAT))->appendIcon('calendar')->addGroupClass('due_date') !!}
{!! Former::text('partial')->data_bind("value: partial, valueUpdate: 'afterkeydown'")->onchange('onPartialChange()') {!! Former::text('partial')->data_bind("value: partial, valueUpdate: 'afterkeydown'")->onkeyup('onPartialChange()')
->rel('tooltip')->data_toggle('tooltip')->data_placement('bottom')->title(trans('texts.partial_value')) !!} ->addGroupClass('partial')!!}
</div> </div>
@if ($entityType == ENTITY_INVOICE) @if ($entityType == ENTITY_INVOICE)
<div data-bind="visible: is_recurring" style="display: none"> <div data-bind="visible: is_recurring" style="display: none">
@ -1322,6 +1318,8 @@
// check invoice number is unique // check invoice number is unique
if ($('.invoice-number').hasClass('has-error')) { if ($('.invoice-number').hasClass('has-error')) {
return false; return false;
} else if ($('.partial').hasClass('has-error')) {
return false;
} }
if (!isSaveValid()) { if (!isSaveValid()) {
@ -1337,8 +1335,6 @@
return false; return false;
} }
onPartialChange(true);
@if (Auth::user()->canCreateOrEdit(ENTITY_INVOICE, $invoice)) @if (Auth::user()->canCreateOrEdit(ENTITY_INVOICE, $invoice))
return true; return true;
@else @else
@ -1477,19 +1473,30 @@
//NINJA.formIsChanged = true; //NINJA.formIsChanged = true;
} }
function onPartialChange(silent) function onPartialChange()
{ {
var val = NINJA.parseFloat($('#partial').val()); var val = NINJA.parseFloat($('#partial').val());
var oldVal = val; var oldVal = val;
val = Math.max(Math.min(val, model.invoice().totals.rawTotal()), 0); val = Math.max(Math.min(val, model.invoice().totals.rawTotal()), 0);
model.invoice().partial(val || '');
if (!silent && val != oldVal) { if (val != oldVal) {
$('#partial').tooltip('show'); console.log('1');
setTimeout(function() { if ($('.partial').hasClass('has-error')) {
$('#partial').tooltip('hide'); return;
}, 5000);
} }
console.log('2');
$('.partial')
.addClass('has-error')
.find('div')
.append('<span class="help-block">{{ trans('texts.partial_value') }}</span>');
} else {
console.log('3');
$('.partial')
.removeClass('has-error')
.find('span')
.hide();
}
} }
function onRecurringEnabled() function onRecurringEnabled()