1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Working on subscriptions UI

This commit is contained in:
Hillel Coren 2017-11-29 13:12:20 +02:00
parent a44bcdad21
commit f5a5881454
7 changed files with 32 additions and 30 deletions

View File

@ -24,15 +24,8 @@ class IntegrationController extends Controller
return Response::json('Event is invalid', 500);
}
$subscription = Subscription::where('account_id', '=', Auth::user()->account_id)
->where('event_id', '=', $eventId)->first();
if (! $subscription) {
$subscription = new Subscription();
$subscription->account_id = Auth::user()->account_id;
$subscription->event_id = $eventId;
}
$subscription = Subscription::createNew();
$subscription->event_id = $eventId;
$subscription->target_url = trim(Input::get('target_url'));
$subscription->save();

View File

@ -132,21 +132,25 @@ class SubscriptionListener
return;
}
$subscription = $entity->account->getSubscription($eventId);
$subscriptions = $entity->account->getSubscriptions($eventId);
if ($subscription) {
$manager = new Manager();
$manager->setSerializer(new ArraySerializer());
$manager->parseIncludes($include);
if (! $subscriptions->count()) {
return;
}
$resource = new Item($entity, $transformer, $entity->getEntityType());
$data = $manager->createData($resource)->toArray();
$manager = new Manager();
$manager->setSerializer(new ArraySerializer());
$manager->parseIncludes($include);
// For legacy Zapier support
if (isset($data['client_id'])) {
$data['client_name'] = $entity->client->getDisplayName();
}
$resource = new Item($entity, $transformer, $entity->getEntityType());
$data = $manager->createData($resource)->toArray();
// For legacy Zapier support
if (isset($data['client_id'])) {
$data['client_name'] = $entity->client->getDisplayName();
}
foreach ($subscriptions as $subscription) {
Utils::notifyZapier($subscription, $data);
}
}

View File

@ -1285,9 +1285,9 @@ class Account extends Eloquent
*
* @return \Illuminate\Database\Eloquent\Model|null|static
*/
public function getSubscription($eventId)
public function getSubscriptions($eventId)
{
return Subscription::where('account_id', '=', $this->id)->where('event_id', '=', $eventId)->first();
return Subscription::where('account_id', '=', $this->id)->where('event_id', '=', $eventId)->get();
}
/**

View File

@ -38,5 +38,12 @@ class Subscription extends EntityModel
return ENTITY_SUBSCRIPTION;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function account()
{
return $this->belongsTo('App\Models\Account');
}
}

View File

@ -71,7 +71,10 @@ class AddSubdomainToLookups extends Migration
});
$accountPublicIds = [];
foreach (Subscription::withTrashed()->orderBy('id')->get() as $subscription) {
foreach (Subscription::withTrashed()
->with('account.users')
->orderBy('id')
->get() as $subscription) {
$accountId = $subscription->account_id;
if (isset($accountPublicIds[$accountId])) {
$publicId = $accountPublicIds[$accountId];
@ -81,6 +84,7 @@ class AddSubdomainToLookups extends Migration
$accountPublicIds[$accountId] = 2;
}
$subscription->public_id = $publicId;
$subscription->user_id = $subscription->account->users[0]->id;
$subscription->save();
}

View File

@ -126,8 +126,3 @@ To email an invoice use the email_invoice command passing the id of the invoice.
curl -X POST ninja.dev/api/v1/email_invoice -d '{"id":1}' \
-H "Content-Type:application/json" -H "X-Ninja-Token: TOKEN"
Subscriptions
"""""""""""""
You can use subscriptions to have Invoice Ninja POST newly created records to a third-party application. To enable this feature you need to manually add a record to the subscriptions table. To determine the event_id find the associated EVENT_CREATE_ value from app/Constants.php.

View File

@ -29,8 +29,7 @@
->setOptions('aoColumnDefs', [['bSortable'=>false, 'aTargets'=>[2]]])
->render('datatable') !!}
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;<br/>&nbsp;</p>
<div class="pull-right">
@if (Utils::hasFeature(FEATURE_API))