bug fix to expense module - was not able to add a contact to a new vendor

This commit is contained in:
steenrabol 2016-01-15 11:31:12 +01:00
parent 172c1a0548
commit f550e3734f
7 changed files with 77 additions and 62 deletions

View File

@ -167,7 +167,8 @@ class VendorController extends BaseController
'data' => Input::old('data'), 'data' => Input::old('data'),
'account' => Auth::user()->account, 'account' => Auth::user()->account,
'sizes' => Cache::get('sizes'), 'sizes' => Cache::get('sizes'),
'paymentTerms' => Cache::get('paymentTerms'), //'paymentTerms' => Cache::get('paymentTerms'),
'paymentTerms' => PaymentTerm::get(),
'industries' => Cache::get('industries'), 'industries' => Cache::get('industries'),
'currencies' => Cache::get('currencies'), 'currencies' => Cache::get('currencies'),
'languages' => Cache::get('languages'), 'languages' => Cache::get('languages'),

View File

@ -200,7 +200,7 @@ Route::group(['middleware' => 'auth'], function() {
Route::get('expenses/create/{vendor_id?}', 'ExpenseController@create'); Route::get('expenses/create/{vendor_id?}', 'ExpenseController@create');
Route::post('expenses/bulk', 'ExpenseController@bulk'); Route::post('expenses/bulk', 'ExpenseController@bulk');
Route::get('api/expense/', array('as'=>'api.expenses', 'uses'=>'ExpenseController@getDatatable')); Route::get('api/expense/', array('as'=>'api.expenses', 'uses'=>'ExpenseController@getDatatable'));
Route::get('api/expenseactivities/{vendor_id?}', array('as'=>'api.expenseactivities', 'uses'=>'ExpenseActivityController@getDatatable')); Route::get('api/expenseactivities/{expense_id?}', array('as'=>'api.expenseactivities', 'uses'=>'ExpenseActivityController@getDatatable'));
}); });

View File

@ -4,6 +4,7 @@ use Laracasts\Presenter\PresentableTrait;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Events\ExpenseWasCreated; use App\Events\ExpenseWasCreated;
use App\Events\ExpenseWasUpdated; use App\Events\ExpenseWasUpdated;
use App\Events\ExpenseWasDeleted;
class Expense extends EntityModel class Expense extends EntityModel
{ {
@ -91,5 +92,10 @@ Expense::updated(function ($expense) {
event(new ExpenseWasUpdated($expense)); event(new ExpenseWasUpdated($expense));
}); });
Expense::deleting(function ($expense) {
$expense->setNullValues();
});
Expense::deleted(function ($expense) {
event(new ExpenseWasDeleted($expense));
});

View File

@ -282,3 +282,11 @@ Vendor::updated(function ($vendor) {
event(new VendorWasUpdated($vendor)); event(new VendorWasUpdated($vendor));
}); });
Vendor::deleting(function ($vendor) {
$vendor->setNullValues();
});
Vendor::deleted(function ($vendor) {
event(new VendorWasDeleted($vendor));
});

View File

@ -74,12 +74,11 @@
<div class="tab-pane active" id="activity"> <div class="tab-pane active" id="activity">
{!! Datatable::table() {!! Datatable::table()
->addColumn( ->addColumn(
trans('texts.date'), trans('texts.expense_date'),
trans('texts.message'), trans('texts.message'),
trans('texts.balance'), trans('texts.amount'),
trans('texts.adjustment')) trans('texts.public_notes'))
->setUrl(url('api/expenseactivities/'. $expense->public_id)) ->setUrl(url('api/expenseactivities/'. $expense->public_id))
->setCustomValues('entityType', 'activity')
->setOptions('sPaginationType', 'bootstrap') ->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false) ->setOptions('bFilter', false)
->setOptions('aaSorting', [['0', 'desc']]) ->setOptions('aaSorting', [['0', 'desc']])
@ -98,6 +97,7 @@
$('.primaryDropDown:not(.dropdown-toggle)').click(function() { $('.primaryDropDown:not(.dropdown-toggle)').click(function() {
window.location = '{{ URL::to('expenses/create/' . $expense->public_id ) }}'; window.location = '{{ URL::to('expenses/create/' . $expense->public_id ) }}';
}); });
}); });
function onArchiveClick() { function onArchiveClick() {

View File

@ -7,8 +7,8 @@
@section('content') @section('content')
@if ($errors->first('vendor_contacts')) @if ($errors->first('vendorcontacts'))
<div class="alert alert-danger">{{ trans($errors->first('vendor_contacts')) }}</div> <div class="alert alert-danger">{{ trans($errors->first('vendorcontacts')) }}</div>
@endif @endif
<div class="row"> <div class="row">
@ -84,15 +84,15 @@
beforeRemove: hideContact, beforeRemove: hideContact,
afterAdd: showContact }'> afterAdd: showContact }'>
{!! Former::hidden('public_id')->data_bind("value: public_id, valueUpdate: 'afterkeydown', {!! Former::hidden('public_id')->data_bind("value: public_id, valueUpdate: 'afterkeydown',
attr: {name: 'vendor_contacts[' + \$index() + '][public_id]'}") !!} attr: {name: 'vendorcontacts[' + \$index() + '][public_id]'}") !!}
{!! Former::text('first_name')->data_bind("value: first_name, valueUpdate: 'afterkeydown', {!! Former::text('first_name')->data_bind("value: first_name, valueUpdate: 'afterkeydown',
attr: {name: 'vendor_contacts[' + \$index() + '][first_name]'}") !!} attr: {name: 'vendorcontacts[' + \$index() + '][first_name]'}") !!}
{!! Former::text('last_name')->data_bind("value: last_name, valueUpdate: 'afterkeydown', {!! Former::text('last_name')->data_bind("value: last_name, valueUpdate: 'afterkeydown',
attr: {name: 'vendor_contacts[' + \$index() + '][last_name]'}") !!} attr: {name: 'vendorcontacts[' + \$index() + '][last_name]'}") !!}
{!! Former::text('email')->data_bind("value: email, valueUpdate: 'afterkeydown', {!! Former::text('email')->data_bind("value: email, valueUpdate: 'afterkeydown',
attr: {name: 'vendor_contacts[' + \$index() + '][email]', id:'email'+\$index()}") !!} attr: {name: 'vendorcontacts[' + \$index() + '][email]', id:'email'+\$index()}") !!}
{!! Former::text('phone')->data_bind("value: phone, valueUpdate: 'afterkeydown', {!! Former::text('phone')->data_bind("value: phone, valueUpdate: 'afterkeydown',
attr: {name: 'vendor_contacts[' + \$index() + '][phone]'}") !!} attr: {name: 'vendorcontacts[' + \$index() + '][phone]'}") !!}
<div class="form-group"> <div class="form-group">
<div class="col-lg-8 col-lg-offset-4 bold"> <div class="col-lg-8 col-lg-offset-4 bold">
@ -175,10 +175,10 @@
function VendorModel(data) { function VendorModel(data) {
var self = this; var self = this;
self.vendor_contacts = ko.observableArray(); self.vendorcontacts = ko.observableArray();
self.mapping = { self.mapping = {
'vendor_contacts': { 'vendorcontacts': {
create: function(options) { create: function(options) {
return new VendorContactModel(options.data); return new VendorContactModel(options.data);
} }
@ -188,12 +188,12 @@
if (data) { if (data) {
ko.mapping.fromJS(data, self.mapping, this); ko.mapping.fromJS(data, self.mapping, this);
} else { } else {
self.vendor_contacts.push(new VendorContactModel()); self.vendorcontacts.push(new VendorContactModel());
} }
self.placeholderName = ko.computed(function() { self.placeholderName = ko.computed(function() {
if (self.vendor_contacts().length == 0) return ''; if (self.vendorcontacts().length == 0) return '';
var contact = self.vendor_contacts()[0]; var contact = self.vendorcontacts()[0];
if (contact.first_name() || contact.last_name()) { if (contact.first_name() || contact.last_name()) {
return contact.first_name() + ' ' + contact.last_name(); return contact.first_name() + ' ' + contact.last_name();
} else { } else {

View File

@ -194,7 +194,7 @@
trans('texts.credit_balance'), trans('texts.credit_balance'),
trans('texts.credit_date'), trans('texts.credit_date'),
trans('texts.private_notes')) trans('texts.private_notes'))
->setUrl(url('api/credits/' . $vendor->public_id)) ->setUrl(url('api/expenses/' . $vendor->public_id))
->setCustomValues('entityType', 'credits') ->setCustomValues('entityType', 'credits')
->setOptions('sPaginationType', 'bootstrap') ->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false) ->setOptions('bFilter', false)