diff --git a/app/Http/Controllers/VendorController.php b/app/Http/Controllers/VendorController.php index 7fac33b1f840..b42eef837efb 100644 --- a/app/Http/Controllers/VendorController.php +++ b/app/Http/Controllers/VendorController.php @@ -75,9 +75,9 @@ class VendorController extends BaseController public function store(CreateVendorRequest $request) { $vendor = $this->vendorService->save($request->input()); - + Session::flash('message', trans('texts.created_vendor')); - + return redirect()->to($vendor->getRoute()); } @@ -167,7 +167,8 @@ class VendorController extends BaseController 'data' => Input::old('data'), 'account' => Auth::user()->account, 'sizes' => Cache::get('sizes'), - 'paymentTerms' => Cache::get('paymentTerms'), + //'paymentTerms' => Cache::get('paymentTerms'), + 'paymentTerms' => PaymentTerm::get(), 'industries' => Cache::get('industries'), 'currencies' => Cache::get('currencies'), 'languages' => Cache::get('languages'), @@ -186,9 +187,9 @@ class VendorController extends BaseController public function update(UpdateVendorRequest $request) { $vendor = $this->vendorService->save($request->input()); - + Session::flash('message', trans('texts.updated_vendor')); - + return redirect()->to($vendor->getRoute()); } diff --git a/app/Http/routes.php b/app/Http/routes.php index 2e1262fb6e27..61a180c2746e 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -87,7 +87,7 @@ Route::group(['middleware' => 'auth'], 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('api/users', array('as'=>'api.users', 'uses'=>'UserController@getDatatable')); Route::resource('users', 'UserController'); Route::post('users/bulk', 'UserController@bulk'); @@ -118,18 +118,18 @@ Route::group(['middleware' => 'auth'], function() { Route::post('settings/cancel_account', 'AccountController@cancelAccount'); Route::get('settings/{section?}', 'AccountController@showSection'); Route::post('settings/{section?}', 'AccountController@doSection'); - + // Payment term Route::get('api/payment_terms', array('as'=>'api.payment_terms', 'uses'=>'PaymentTermController@getDatatable')); Route::resource('payment_terms', 'PaymentTermController'); Route::post('payment_terms/bulk', 'PaymentTermController@bulk'); - + Route::get('account/getSearchData', array('as' => 'getSearchData', 'uses' => 'AccountController@getSearchData')); Route::post('user/setTheme', 'UserController@setTheme'); Route::post('remove_logo', 'AccountController@removeLogo'); Route::post('account/go_pro', 'AccountController@enableProPlan'); - + Route::post('/export', 'ExportController@doExport'); Route::post('/import', 'ImportController@doImport'); Route::post('/import_csv', 'ImportController@doImportCSV'); @@ -149,10 +149,10 @@ Route::group(['middleware' => 'auth'], function() { Route::post('tasks/bulk', 'TaskController@bulk'); Route::get('api/recurring_invoices/{client_id?}', array('as'=>'api.recurring_invoices', 'uses'=>'InvoiceController@getRecurringDatatable')); - + Route::get('invoices/invoice_history/{invoice_id}', 'InvoiceController@invoiceHistory'); Route::get('quotes/quote_history/{invoice_id}', 'InvoiceController@invoiceHistory'); - + Route::resource('invoices', 'InvoiceController'); Route::get('api/invoices/{client_id?}', array('as'=>'api.invoices', 'uses'=>'InvoiceController@getDatatable')); Route::get('invoices/create/{client_id?}', 'InvoiceController@create'); @@ -188,7 +188,7 @@ Route::group(['middleware' => 'auth'], function() { get('/resend_confirmation', 'AccountController@resendConfirmation'); post('/update_setup', 'AppController@updateSetup'); - + // vendor Route::resource('vendors', 'VendorController'); Route::get('api/vendor', array('as'=>'api.vendors', 'uses'=>'VendorController@getDatatable')); @@ -200,8 +200,8 @@ Route::group(['middleware' => 'auth'], function() { Route::get('expenses/create/{vendor_id?}', 'ExpenseController@create'); Route::post('expenses/bulk', 'ExpenseController@bulk'); 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')); + }); // Route groups for API @@ -287,11 +287,11 @@ if (!defined('CONTACT_EMAIL')) { define('ENTITY_EXPENSE', 'expense'); define('ENTITY_PAYMENT_TERM','payment_term'); define('ENTITY_EXPENSE_ACTIVITY','expense_activity'); - + define('PERSON_CONTACT', 'contact'); define('PERSON_USER', 'user'); define('PERSON_VENDOR_CONTACT','vendorcontact'); - + define('BASIC_SETTINGS', 'basic_settings'); define('ADVANCED_SETTINGS', 'advanced_settings'); @@ -369,7 +369,7 @@ if (!defined('CONTACT_EMAIL')) { define('ACTIVITY_TYPE_ARCHIVE_EXPENSE', 35); define('ACTIVITY_TYPE_DELETE_EXPENSE', 36); define('ACTIVITY_TYPE_RESTORE_EXPENSE', 37); - + define('DEFAULT_INVOICE_NUMBER', '0001'); define('RECENTLY_VIEWED_LIMIT', 8); define('LOGGED_ERROR_LIMIT', 100); @@ -404,7 +404,7 @@ if (!defined('CONTACT_EMAIL')) { define('MAX_NUM_VENDORS', 100); define('MAX_NUM_VENDORS_PRO', 20000); define('MAX_NUM_VENDORS_LEGACY', 500); - + define('INVOICE_STATUS_DRAFT', 1); define('INVOICE_STATUS_SENT', 2); define('INVOICE_STATUS_VIEWED', 3); diff --git a/app/Models/Expense.php b/app/Models/Expense.php index a666f558cf0b..daf652d4e415 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -4,13 +4,14 @@ use Laracasts\Presenter\PresentableTrait; use Illuminate\Database\Eloquent\SoftDeletes; use App\Events\ExpenseWasCreated; use App\Events\ExpenseWasUpdated; +use App\Events\ExpenseWasDeleted; class Expense extends EntityModel { // Expenses use SoftDeletes; use PresentableTrait; - + protected $dates = ['deleted_at']; protected $presenter = 'App\Ninja\Presenters\ExpensePresenter'; @@ -20,7 +21,7 @@ class Expense extends EntityModel 'exchange_rate', 'private_notes', 'public_notes', - ]; + ]; public function account() { return $this->belongsTo('App\Models\Account'); @@ -40,10 +41,10 @@ class Expense extends EntityModel { if($this->expense_number) return $this->expense_number; - + return $this->public_id; } - + public function getDisplayName() { return $this->getName(); @@ -53,7 +54,7 @@ class Expense extends EntityModel { return "/expenses/{$this->public_id}"; } - + public function getEntityType() { return ENTITY_EXPENSE; @@ -91,5 +92,10 @@ Expense::updated(function ($expense) { event(new ExpenseWasUpdated($expense)); }); +Expense::deleting(function ($expense) { + $expense->setNullValues(); +}); - +Expense::deleted(function ($expense) { + event(new ExpenseWasDeleted($expense)); +}); diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index c228c636011b..0fc8aff3666c 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -154,7 +154,7 @@ class Vendor extends EntityModel $this->balance = $this->balance + $balanceAdjustment; $this->paid_to_date = $this->paid_to_date + $paidToDateAdjustment; - + $this->save(); } @@ -167,18 +167,18 @@ class Vendor extends EntityModel { return 0; } - + public function getName() { return $this->name; } - + public function getDisplayName() { if ($this->name) { return $this->name; } - + if ( ! count($this->contacts)) { return ''; } @@ -236,7 +236,7 @@ class Vendor extends EntityModel } $accountGateway = $this->account->getGatewayConfig(GATEWAY_STRIPE); - + if (!$accountGateway) { return false; } @@ -282,3 +282,11 @@ Vendor::updated(function ($vendor) { event(new VendorWasUpdated($vendor)); }); + +Vendor::deleting(function ($vendor) { + $vendor->setNullValues(); +}); + +Vendor::deleted(function ($vendor) { + event(new VendorWasDeleted($vendor)); +}); diff --git a/resources/views/expenses/show.blade.php b/resources/views/expenses/show.blade.php index f8d83d97350b..dd0c613b7a3c 100644 --- a/resources/views/expenses/show.blade.php +++ b/resources/views/expenses/show.blade.php @@ -74,12 +74,11 @@
{!! Datatable::table() ->addColumn( - trans('texts.date'), + trans('texts.expense_date'), trans('texts.message'), - trans('texts.balance'), - trans('texts.adjustment')) + trans('texts.amount'), + trans('texts.public_notes')) ->setUrl(url('api/expenseactivities/'. $expense->public_id)) - ->setCustomValues('entityType', 'activity') ->setOptions('sPaginationType', 'bootstrap') ->setOptions('bFilter', false) ->setOptions('aaSorting', [['0', 'desc']]) @@ -98,6 +97,7 @@ $('.primaryDropDown:not(.dropdown-toggle)').click(function() { window.location = '{{ URL::to('expenses/create/' . $expense->public_id ) }}'; }); + }); function onArchiveClick() { diff --git a/resources/views/vendors/edit.blade.php b/resources/views/vendors/edit.blade.php index aaf25c1c0ee5..ef37f3dec67b 100644 --- a/resources/views/vendors/edit.blade.php +++ b/resources/views/vendors/edit.blade.php @@ -7,8 +7,8 @@ @section('content') -@if ($errors->first('vendor_contacts')) -
{{ trans($errors->first('vendor_contacts')) }}
+@if ($errors->first('vendorcontacts')) +
{{ trans($errors->first('vendorcontacts')) }}
@endif
@@ -19,7 +19,7 @@ ['email' => 'email'] )->addClass('col-md-12 warn-on-exit') ->method($method) !!} - + @include('partials.autocomplete_fix') @if ($vendor) @@ -36,13 +36,13 @@

{!! trans('texts.organization') !!}

- + {!! Former::text('name')->data_bind("attr { placeholder: placeholderName }") !!} {!! Former::text('id_number') !!} {!! Former::text('vat_number') !!} {!! Former::text('website') !!} {!! Former::text('work_phone') !!} - + @if (Auth::user()->isPro()) @if ($customLabel1) {!! Former::text('custom_value1')->label($customLabel1) !!} @@ -59,7 +59,7 @@

{!! trans('texts.address') !!}

- + {!! Former::text('address1') !!} {!! Former::text('address2') !!} {!! Former::text('city') !!} @@ -84,21 +84,21 @@ beforeRemove: hideContact, afterAdd: showContact }'> {!! Former::hidden('public_id')->data_bind("value: public_id, valueUpdate: 'afterkeydown', - attr: {name: 'vendor_contacts[' + \$index() + '][public_id]'}") !!} - {!! Former::text('first_name')->data_bind("value: first_name, valueUpdate: 'afterkeydown', - attr: {name: 'vendor_contacts[' + \$index() + '][first_name]'}") !!} + attr: {name: 'vendorcontacts[' + \$index() + '][public_id]'}") !!} + {!! Former::text('first_name')->data_bind("value: first_name, valueUpdate: 'afterkeydown', + attr: {name: 'vendorcontacts[' + \$index() + '][first_name]'}") !!} {!! Former::text('last_name')->data_bind("value: last_name, valueUpdate: 'afterkeydown', - attr: {name: 'vendor_contacts[' + \$index() + '][last_name]'}") !!} - {!! Former::text('email')->data_bind("value: email, valueUpdate: 'afterkeydown', - attr: {name: 'vendor_contacts[' + \$index() + '][email]', id:'email'+\$index()}") !!} + attr: {name: 'vendorcontacts[' + \$index() + '][last_name]'}") !!} + {!! Former::text('email')->data_bind("value: email, valueUpdate: 'afterkeydown', + attr: {name: 'vendorcontacts[' + \$index() + '][email]', id:'email'+\$index()}") !!} {!! Former::text('phone')->data_bind("value: phone, valueUpdate: 'afterkeydown', - attr: {name: 'vendor_contacts[' + \$index() + '][phone]'}") !!} + attr: {name: 'vendorcontacts[' + \$index() + '][phone]'}") !!}
{!! link_to('#', trans('texts.remove_contact').' -', array('data-bind'=>'click: $parent.removeContact')) !!} - + {!! link_to('#', trans('texts.add_contact').' +', array('onclick'=>'return addContact()')) !!} @@ -114,7 +114,7 @@

{!! trans('texts.additional_info') !!}

- + {!! Former::select('currency_id')->addOption('','') ->placeholder($account->currency ? $account->currency->name : '') ->fromQuery($currencies, 'name', 'id') !!} @@ -175,10 +175,10 @@ function VendorModel(data) { var self = this; - self.vendor_contacts = ko.observableArray(); + self.vendorcontacts = ko.observableArray(); self.mapping = { - 'vendor_contacts': { + 'vendorcontacts': { create: function(options) { return new VendorContactModel(options.data); } @@ -188,18 +188,18 @@ if (data) { ko.mapping.fromJS(data, self.mapping, this); } else { - self.vendor_contacts.push(new VendorContactModel()); + self.vendorcontacts.push(new VendorContactModel()); } self.placeholderName = ko.computed(function() { - if (self.vendor_contacts().length == 0) return ''; - var contact = self.vendor_contacts()[0]; + if (self.vendorcontacts().length == 0) return ''; + var contact = self.vendorcontacts()[0]; if (contact.first_name() || contact.last_name()) { return contact.first_name() + ' ' + contact.last_name(); } else { return contact.email(); } - }); + }); } @if ($data) diff --git a/resources/views/vendors/show.blade.php b/resources/views/vendors/show.blade.php index 7fea8b976ec2..7be091d7e9e0 100644 --- a/resources/views/vendors/show.blade.php +++ b/resources/views/vendors/show.blade.php @@ -100,13 +100,13 @@ @if ($vendor->private_notes)

{{ $vendor->private_notes }}

@endif - + @if ($vendor->vendor_industry) {{ $vendor->vendor_industry->name }}
@endif @if ($vendor->vendor_size) {{ $vendor->vendor_size->name }}
- @endif + @endif @if ($vendor->website)

{!! Utils::formatWebsite($vendor->website) !!}

@@ -130,7 +130,7 @@ @endif @if ($contact->phone) {{ $contact->phone }}
- @endif + @endif @endforeach
@@ -194,7 +194,7 @@ trans('texts.credit_balance'), trans('texts.credit_date'), trans('texts.private_notes')) - ->setUrl(url('api/credits/' . $vendor->public_id)) + ->setUrl(url('api/expenses/' . $vendor->public_id)) ->setCustomValues('entityType', 'credits') ->setOptions('sPaginationType', 'bootstrap') ->setOptions('bFilter', false) @@ -266,14 +266,14 @@ var map = new google.maps.Map(mapCanvas, mapOptions) var address = "{{ "{$vendor->address1} {$vendor->address2} {$vendor->city} {$vendor->state} {$vendor->postal_code} " . ($vendor->country ? $vendor->country->name : '') }}"; - + geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if (status != google.maps.GeocoderStatus.ZERO_RESULTS) { var result = results[0]; map.setCenter(result.geometry.location); - + var infowindow = new google.maps.InfoWindow( { content: ''+result.formatted_address+'', size: new google.maps.Size(150, 50) @@ -281,9 +281,9 @@ var marker = new google.maps.Marker({ position: result.geometry.location, - map: map, + map: map, title:address, - }); + }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map, marker); });