mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-19 16:01:34 +02:00
Working on subscriptions UI
This commit is contained in:
parent
d936d48641
commit
a44bcdad21
@ -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);
|
||||
|
@ -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'));
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
40
app/Ninja/Datatables/SubscriptionDatatable.php
Normal file
40
app/Ninja/Datatables/SubscriptionDatatable.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Datatables;
|
||||
|
||||
use URL;
|
||||
|
||||
class SubscriptionDatatable extends EntityDatatable
|
||||
{
|
||||
public $entityType = ENTITY_SUBSCRIPTION;
|
||||
|
||||
public function columns()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'event',
|
||||
function ($model) {
|
||||
return trans('texts.subscription_event_' . $model->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");
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
18
app/Policies/SubscriptionPolicy.php
Normal file
18
app/Policies/SubscriptionPolicy.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class SubscriptionPolicy extends EntityPolicy
|
||||
{
|
||||
public static function edit(User $user, $item)
|
||||
{
|
||||
return $user->hasPermission('admin');
|
||||
}
|
||||
|
||||
public static function create(User $user, $item)
|
||||
{
|
||||
return $user->hasPermission('admin');
|
||||
}
|
||||
}
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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',
|
||||
|
||||
|
||||
);
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
->render('datatable') !!}
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<div class="pull-right">
|
||||
@if (Utils::hasFeature(FEATURE_API))
|
||||
@ -37,14 +38,14 @@
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@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 @@
|
||||
|
||||
</script>
|
||||
|
||||
<p> </p>
|
||||
|
||||
|
||||
@if (!Utils::isReseller())
|
||||
<p> </p>
|
||||
<script src="https://zapier.com/zapbook/embed/widget.js?guided_zaps=5627,6025,12216,8805,5628,6027&container=false&limit=6"></script>
|
||||
|
@ -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')!!}
|
||||
|
||||
</div>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<div style="display:none">
|
||||
{!! 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() !!}
|
||||
</div>
|
||||
|
||||
@ -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();
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user