diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 911238291156..027e27307749 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -475,16 +475,9 @@ class AccountController extends BaseController */ private function showProducts() { - $columns = ['product', 'description', 'unit_cost']; - if (Auth::user()->account->invoice_item_taxes) { - $columns[] = 'tax_rate'; - } - $columns[] = 'action'; - $data = [ 'account' => Auth::user()->account, 'title' => trans('texts.product_library'), - 'columns' => Utils::trans($columns), ]; return View::make('accounts.products', $data); diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 626edbae2f1e..e89391eb3cd1 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -3,6 +3,7 @@ use Auth; use URL; use View; +use Utils; use Input; use Session; use Redirect; @@ -22,7 +23,7 @@ class ProductController extends BaseController /** * ProductController constructor. - * + * * @param ProductService $productService */ public function __construct(ProductService $productService) @@ -37,9 +38,34 @@ class ProductController extends BaseController */ public function index() { - return Redirect::to('settings/' . ACCOUNT_PRODUCTS); + $columns = [ + 'checkbox', + 'product', + 'description', + 'unit_cost' + ]; + + if (Auth::user()->account->invoice_item_taxes) { + $columns[] = 'tax_rate'; + } + $columns[] = 'action'; + + return View::make('list', [ + 'entityType' => ENTITY_PRODUCT, + 'title' => trans('texts.products'), + 'sortCol' => '4', + 'columns' => Utils::trans($columns), + ]); } + public function show($publicId) + { + Session::reflash(); + + return Redirect::to("products/$publicId/edit"); + } + + /** * @return \Illuminate\Http\JsonResponse */ @@ -126,7 +152,7 @@ class ProductController extends BaseController $message = $productPublicId ? trans('texts.updated_product') : trans('texts.created_product'); Session::flash('message', $message); - return Redirect::to('settings/' . ACCOUNT_PRODUCTS); + return Redirect::to(ACCOUNT_PRODUCTS); } /** @@ -134,12 +160,12 @@ class ProductController extends BaseController */ public function bulk() { - $action = Input::get('bulk_action'); - $ids = Input::get('bulk_public_id'); + $action = Input::get('action'); + $ids = Input::get('public_id') ? Input::get('public_id') : Input::get('ids'); $count = $this->productService->bulk($ids, $action); Session::flash('message', trans('texts.archived_product')); - return Redirect::to('settings/' . ACCOUNT_PRODUCTS); + return $this->returnBulk(ENTITY_PRODUCT, $action, $ids); } } diff --git a/app/Http/routes.php b/app/Http/routes.php index 42bfe2c44f80..e5f567bbcf2c 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -188,6 +188,11 @@ Route::group(['middleware' => 'auth:user'], function() { Route::get('api/credits/{client_id?}', ['as'=>'api.credits', 'uses'=>'CreditController@getDatatable']); Route::post('credits/bulk', 'CreditController@bulk'); + Route::get('api/products', ['as'=>'api.products', 'uses'=>'ProductController@getDatatable']); + Route::resource('products', 'ProductController'); + Route::post('products/bulk', 'ProductController@bulk'); + + Route::get('/resend_confirmation', 'AccountController@resendConfirmation'); Route::post('/update_setup', 'AppController@updateSetup'); @@ -230,10 +235,6 @@ Route::group([ Route::resource('tokens', 'TokenController'); Route::post('tokens/bulk', 'TokenController@bulk'); - Route::get('api/products', ['as'=>'api.products', 'uses'=>'ProductController@getDatatable']); - Route::resource('products', 'ProductController'); - Route::post('products/bulk', 'ProductController@bulk'); - Route::get('api/tax_rates', ['as'=>'api.tax_rates', 'uses'=>'TaxRateController@getDatatable']); Route::resource('tax_rates', 'TaxRateController'); Route::post('tax_rates/bulk', 'TaxRateController@bulk'); diff --git a/app/Models/EntityModel.php b/app/Models/EntityModel.php index 7bf0341e9276..968ff961b175 100644 --- a/app/Models/EntityModel.php +++ b/app/Models/EntityModel.php @@ -254,6 +254,7 @@ class EntityModel extends Eloquent $icons = [ 'dashboard' => 'tachometer', 'clients' => 'users', + 'products' => 'cube', 'invoices' => 'file-pdf-o', 'payments' => 'credit-card', 'recurring_invoices' => 'files-o', diff --git a/app/Ninja/Repositories/ProductRepository.php b/app/Ninja/Repositories/ProductRepository.php index bf20e0317103..bcf2dfa56f2b 100644 --- a/app/Ninja/Repositories/ProductRepository.php +++ b/app/Ninja/Repositories/ProductRepository.php @@ -19,13 +19,12 @@ class ProductRepository extends BaseRepository public function find($accountId) { - return DB::table('products') + $query = DB::table('products') ->leftJoin('tax_rates', function($join) { $join->on('tax_rates.id', '=', 'products.default_tax_rate_id') ->whereNull('tax_rates.deleted_at'); }) ->where('products.account_id', '=', $accountId) - ->where('products.deleted_at', '=', null) ->select( 'products.public_id', 'products.product_key', @@ -35,6 +34,12 @@ class ProductRepository extends BaseRepository 'tax_rates.rate as tax_rate', 'products.deleted_at' ); + + if (!\Session::get('show_trash:product')) { + $query->where('products.deleted_at', '=', null); + } + + return $query; } public function save($data, $product = null) diff --git a/app/Policies/ProductPolicy.php b/app/Policies/ProductPolicy.php index 10f8b13eee0e..23ce11fc7570 100644 --- a/app/Policies/ProductPolicy.php +++ b/app/Policies/ProductPolicy.php @@ -10,20 +10,4 @@ use App\Models\User; class ProductPolicy extends EntityPolicy { - /** - * @param User $user - * @param $item - * @return mixed - */ - public static function edit(User $user, $item) { - return $user->hasPermission('admin'); - } - - /** - * @param User $user - * @return mixed - */ - public static function create(User $user) { - return $user->hasPermission('admin'); - } -} \ No newline at end of file +} diff --git a/app/Services/ProductService.php b/app/Services/ProductService.php index 220ac08a60a9..d5a23a57caee 100644 --- a/app/Services/ProductService.php +++ b/app/Services/ProductService.php @@ -1,5 +1,7 @@ productRepo->find($accountId); + if(!Utils::hasPermission('view_all')){ + $query->where('products.user_id', '=', Auth::user()->id); + } + return $this->datatableService->createDatatable($datatable, $query); } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index fe9cd71b69c2..5d13273d92c7 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -287,7 +287,7 @@ $LANG = array( 'view_as_recipient' => 'View as recipient', 'product_library' => 'Product Library', 'product' => 'Product', - 'products' => 'Product Library', + 'products' => 'Products', 'fill_products' => 'Auto-fill products', 'fill_products_help' => 'Selecting a product will automatically fill in the description and cost', 'update_products' => 'Auto-update products', @@ -2136,7 +2136,7 @@ $LANG = array( 'update' => 'Update', 'invoice_fields_help' => 'Drag and drop fields to change their order and location', 'new_category' => 'New Category', - + 'restore_product' => 'Restore Product', ); diff --git a/resources/views/accounts/product.blade.php b/resources/views/accounts/product.blade.php index d970ea7cbbb9..3c25495ff150 100644 --- a/resources/views/accounts/product.blade.php +++ b/resources/views/accounts/product.blade.php @@ -1,13 +1,11 @@ @extends('header') -@section('content') +@section('content') @parent - @include('accounts.nav', ['selected' => ACCOUNT_PRODUCTS]) - {!! Former::open($url)->method($method) ->rules(['product_key' => 'required|max:255']) - ->addClass('warn-on-exit') !!} + ->addClass('col-md-10 col-md-offset-1 warn-on-exit') !!}