diff --git a/app/Constants.php b/app/Constants.php index dea9f2936848..601bade99ec8 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -40,6 +40,7 @@ if (! defined('APP_NAME')) { define('ENTITY_PROJECT', 'project'); define('ENTITY_RECURRING_EXPENSE', 'recurring_expense'); define('ENTITY_CUSTOMER', 'customer'); + define('ENTITY_SUBSCRIPTION', 'subscription'); define('INVOICE_TYPE_STANDARD', 1); define('INVOICE_TYPE_QUOTE', 2); diff --git a/app/Http/Controllers/SubscriptionController.php b/app/Http/Controllers/SubscriptionController.php index 3a5157def579..82d4d2fcbc9b 100644 --- a/app/Http/Controllers/SubscriptionController.php +++ b/app/Http/Controllers/SubscriptionController.php @@ -47,7 +47,7 @@ class SubscriptionController extends BaseController */ public function getDatatable() { - return $this->subscriptionService->getDatatable(Auth::user()->id); + return $this->subscriptionService->getDatatable(Auth::user()->account_id); } /** @@ -109,6 +109,7 @@ class SubscriptionController extends BaseController { $action = Input::get('bulk_action'); $ids = Input::get('bulk_public_id'); + $count = $this->subscriptionService->bulk($ids, $action); Session::flash('message', trans('texts.archived_subscription')); diff --git a/app/Models/Subscription.php b/app/Models/Subscription.php index 23e04ad7a0b5..a01a30e7f445 100644 --- a/app/Models/Subscription.php +++ b/app/Models/Subscription.php @@ -14,6 +14,7 @@ class Subscription extends EntityModel * @var bool */ public $timestamps = true; + use SoftDeletes; /** @@ -28,4 +29,14 @@ class Subscription extends EntityModel 'event_id', 'target_url', ]; + + /** + * @return mixed + */ + public function getEntityType() + { + return ENTITY_SUBSCRIPTION; + } + + } diff --git a/app/Ninja/Datatables/SubscriptionDatatable.php b/app/Ninja/Datatables/SubscriptionDatatable.php new file mode 100644 index 000000000000..8538b99391e4 --- /dev/null +++ b/app/Ninja/Datatables/SubscriptionDatatable.php @@ -0,0 +1,40 @@ +event); + }, + ], + [ + 'target', + function ($model) { + return $model->target; + }, + ], + ]; + } + + public function actions() + { + return [ + [ + uctrans('texts.edit_subscription'), + function ($model) { + return URL::to("subscriptions/{$model->public_id}/edit"); + }, + ], + ]; + } +} diff --git a/app/Ninja/Repositories/SubscriptionRepository.php b/app/Ninja/Repositories/SubscriptionRepository.php index 9b11d49b3e2d..b4687f8b192e 100644 --- a/app/Ninja/Repositories/SubscriptionRepository.php +++ b/app/Ninja/Repositories/SubscriptionRepository.php @@ -12,12 +12,18 @@ class SubscriptionRepository extends BaseRepository return 'App\Models\Subscription'; } - public function find($userId) + public function find($accountId) { - $query = DB::table('account_subscriptions') - ->where('account_subscriptions.user_id', '=', $userId) - ->whereNull('account_subscriptions.deleted_at'); + $query = DB::table('subscriptions') + ->where('subscriptions.account_id', '=', $accountId) + ->whereNull('subscriptions.deleted_at') + ->select( + 'subscriptions.public_id', + 'subscriptions.target_url as target', + 'subscriptions.event_id as event', + 'subscriptions.deleted_at' + ); - return $query->select('account_subscriptions.public_id', 'account_subscriptions.name', 'account_subscriptions.subscription', 'account_subscriptions.public_id', 'account_subscriptions.deleted_at'); + return $query; } } diff --git a/app/Policies/SubscriptionPolicy.php b/app/Policies/SubscriptionPolicy.php new file mode 100644 index 000000000000..acdc4146d2eb --- /dev/null +++ b/app/Policies/SubscriptionPolicy.php @@ -0,0 +1,18 @@ +hasPermission('admin'); + } + + public static function create(User $user, $item) + { + return $user->hasPermission('admin'); + } +} diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 54b9df70e60a..97714c29fa6c 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -29,6 +29,7 @@ class AuthServiceProvider extends ServiceProvider \App\Models\TaxRate::class => \App\Policies\TaxRatePolicy::class, \App\Models\AccountGateway::class => \App\Policies\AccountGatewayPolicy::class, \App\Models\AccountToken::class => \App\Policies\TokenPolicy::class, + \App\Models\Subscription::class => \App\Policies\SubscriptionPolicy::class, \App\Models\BankAccount::class => \App\Policies\BankAccountPolicy::class, \App\Models\PaymentTerm::class => \App\Policies\PaymentTermPolicy::class, \App\Models\Project::class => \App\Policies\ProjectPolicy::class, diff --git a/app/Services/SubscriptionService.php b/app/Services/SubscriptionService.php index fcdb26011a5e..9101fe540d22 100644 --- a/app/Services/SubscriptionService.php +++ b/app/Services/SubscriptionService.php @@ -45,10 +45,10 @@ class SubscriptionService extends BaseService * * @return \Illuminate\Http\JsonResponse */ - public function getDatatable($userId) + public function getDatatable($accountId) { $datatable = new SubscriptionDatatable(false); - $query = $this->subscriptionRepo->find($userId); + $query = $this->subscriptionRepo->find($accountId); return $this->datatableService->createDatatable($datatable, $query); } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 7c551f556c6d..4be32c7f719b 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2568,20 +2568,25 @@ $LANG = array( 'apple_pay_not_supported' => 'Sorry, Apple/Google Pay isn\'t supported', 'optional_payment_methods' => 'Optional Payment Methods', 'add_subscription' => 'Add Subscription', - 'target_url' => 'Target URL', + 'target_url' => 'Target', + 'target_url_help' => 'When the selected event occurs the app will post the entity as JSON to the target URL.', 'event' => 'Event', - 'event_create_client' => 'Created Client', - 'event_create_invoice' => 'Created Invoice', - 'event_create_quote' => 'Created Quote', - 'event_create_payment' => 'Created Payment', - 'event_create_vendor' => 'Created Vendor', - 'event_update_quote' => 'Updated Quote', - 'event_delete_quote' => 'Deleted Quote', - 'event_update_invoice' => 'Updated Invoice', - 'event_delete_invoice' => 'Deleted Invoice', + 'subscription_event_1' => 'Created Client', + 'subscription_event_2' => 'Created Invoice', + 'subscription_event_3' => 'Created Quote', + 'subscription_event_4' => 'Created Payment', + 'subscription_event_5' => 'Created Vendor', + 'subscription_event_6' => 'Updated Quote', + 'subscription_event_7' => 'Deleted Quote', + 'subscription_event_8' => 'Updated Invoice', + 'subscription_event_9' => 'Deleted Invoice', 'subscriptions' => 'Subscriptions', 'updated_subscription' => 'Successfully updated subscription', 'created_subscription' => 'Successfully created subscription', + 'edit_subscription' => 'Edit Subscription', + 'archive_subscription' => 'Archive Subscription', + 'archived_subscription' => 'Successfully archived subscription', + ); diff --git a/resources/views/accounts/api_tokens.blade.php b/resources/views/accounts/api_tokens.blade.php index 5769a213de79..5352446ae4a9 100644 --- a/resources/views/accounts/api_tokens.blade.php +++ b/resources/views/accounts/api_tokens.blade.php @@ -30,6 +30,7 @@ ->render('datatable') !!}

 

+

 

@if (Utils::hasFeature(FEATURE_API)) @@ -37,14 +38,14 @@ @endif
- @include('partials.bulk_form', ['entityType' => ENTITY_TOKEN]) + @include('partials.bulk_form', ['entityType' => ENTITY_SUBSCRIPTION]) {!! Datatable::table() ->addColumn( - trans('texts.name'), - trans('texts.token'), + trans('texts.event'), + trans('texts.target_url'), trans('texts.action')) - ->setUrl(url('api/tokens/')) + ->setUrl(url('api/subscriptions/')) ->setOptions('sPaginationType', 'bootstrap') ->setOptions('bFilter', false) ->setOptions('bAutoWidth', false) @@ -59,6 +60,9 @@ +

 

+ + @if (!Utils::isReseller())

 

diff --git a/resources/views/accounts/subscription.blade.php b/resources/views/accounts/subscription.blade.php index 221511d21bfc..856f14c665cb 100644 --- a/resources/views/accounts/subscription.blade.php +++ b/resources/views/accounts/subscription.blade.php @@ -22,25 +22,26 @@ {!! Former::select('event_id') ->options([ trans('texts.clients') => [ - EVENT_CREATE_CLIENT => trans('texts.event_create_client'), + EVENT_CREATE_CLIENT => trans('texts.subscription_event_' . EVENT_CREATE_CLIENT), ], trans('texts.invoices') => [ - EVENT_CREATE_INVOICE => trans('texts.event_create_invoice'), - EVENT_UPDATE_INVOICE => trans('texts.event_update_invoice'), - EVENT_DELETE_INVOICE => trans('texts.event_delete_invoice'), + EVENT_CREATE_INVOICE => trans('texts.subscription_event_' . EVENT_CREATE_INVOICE), + EVENT_UPDATE_INVOICE => trans('texts.subscription_event_' . EVENT_UPDATE_INVOICE), + EVENT_DELETE_INVOICE => trans('texts.subscription_event_' . EVENT_DELETE_INVOICE), ], trans('texts.payments') => [ - EVENT_CREATE_PAYMENT => trans('texts.event_create_payment'), + EVENT_CREATE_PAYMENT => trans('texts.subscription_event_' . EVENT_CREATE_PAYMENT), ], trans('texts.quotes') => [ - EVENT_CREATE_QUOTE => trans('texts.event_create_quote'), - EVENT_UPDATE_QUOTE => trans('texts.event_update_quote'), - EVENT_DELETE_QUOTE => trans('texts.event_delete_quote'), + EVENT_CREATE_QUOTE => trans('texts.subscription_event_' . EVENT_CREATE_QUOTE), + EVENT_UPDATE_QUOTE => trans('texts.subscription_event_' . EVENT_UPDATE_QUOTE), + EVENT_DELETE_QUOTE => trans('texts.subscription_event_' . EVENT_DELETE_QUOTE), ] ]) ->label('event') !!} {!! Former::text('target_url') + ->help('target_url_help') ->placeholder('https://example.com')!!} diff --git a/resources/views/partials/bulk_form.blade.php b/resources/views/partials/bulk_form.blade.php index be3086b24f33..11a5df17ab15 100644 --- a/resources/views/partials/bulk_form.blade.php +++ b/resources/views/partials/bulk_form.blade.php @@ -1,7 +1,7 @@
- {!! Former::open($entityType . 's/bulk')->addClass('bulk-form') !!} - {!! Former::text('bulk_action') !!} - {!! Former::text('bulk_public_id') !!} + {!! Former::open($entityType . 's/bulk')->addClass("bulk-form bulk-{$entityType}-form") !!} + {!! Former::text('bulk_action')->addClass('bulk-action') !!} + {!! Former::text('bulk_public_id')->addClass('bulk-public-id') !!} {!! Former::close() !!}
@@ -21,8 +21,8 @@ } @endif - $('#bulk_public_id').val(id); - $('#bulk_action').val(action); - $('form.bulk-form').submit(); + $('.bulk-public-id').val(id); + $('.bulk-action').val(action); + $('form.bulk-{{ $entityType }}-form').submit(); }