mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Recurring Invoice Invitations
This commit is contained in:
parent
24104509b3
commit
67492c3384
@ -181,6 +181,11 @@ class RecurringInvoice extends BaseModel
|
||||
$this->morphMany(RecurringInvoiceInvitation::class);
|
||||
}
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->morphMany(Document::class, 'documentable');
|
||||
}
|
||||
|
||||
public function getStatusAttribute()
|
||||
{
|
||||
if ($this->status_id == self::STATUS_ACTIVE && $this->next_send_date > Carbon::now()) { //marked as active, but yet to fire first cycle
|
||||
|
@ -11,12 +11,10 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RecurringInvoiceInvitation extends BaseModel
|
||||
{
|
||||
use MakesDates;
|
||||
|
||||
protected $fillable = ['client_contact_id'];
|
||||
|
||||
@ -59,12 +57,5 @@ class RecurringInvoiceInvitation extends BaseModel
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function signatureDiv()
|
||||
{
|
||||
if (! $this->signature_base64) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return sprintf('<img src="data:image/svg+xml;base64,%s"></img><p/>%s: %s', $this->signature_base64, ctrans('texts.signed'), $this->createClientDate($this->signature_date, $this->contact->client->timezone()->name));
|
||||
}
|
||||
}
|
||||
|
33
app/Transformers/RecurringInvoiceInvitationTransformer.php
Normal file
33
app/Transformers/RecurringInvoiceInvitationTransformer.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Transformers;
|
||||
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class RecurringInvoiceInvitationTransformer extends EntityTransformer
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
public function transform(RecurringInvoiceInvitation $invitation)
|
||||
{
|
||||
return [
|
||||
'id' => $this->encodePrimaryKey($invitation->id),
|
||||
'client_contact_id' => $this->encodePrimaryKey($invitation->client_contact_id),
|
||||
'key' => $invitation->key,
|
||||
'updated_at' => (int) $invitation->updated_at,
|
||||
'archived_at' => (int) $invitation->deleted_at,
|
||||
'created_at' => (int) $invitation->created_at,
|
||||
];
|
||||
}
|
||||
}
|
@ -11,8 +11,12 @@
|
||||
|
||||
namespace App\Transformers;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use App\Transformers\DocumentTransformer;
|
||||
use App\Transformers\RecurringInvoiceInvitationTransformer;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class RecurringInvoiceTransformer extends EntityTransformer
|
||||
@ -20,14 +24,15 @@ class RecurringInvoiceTransformer extends EntityTransformer
|
||||
use MakesHash;
|
||||
|
||||
protected $defaultIncludes = [
|
||||
// 'invoice_items',
|
||||
'invitations',
|
||||
'documents',
|
||||
];
|
||||
|
||||
protected $availableIncludes = [
|
||||
// 'invitations',
|
||||
'invitations',
|
||||
'documents',
|
||||
// 'payments',
|
||||
// 'client',
|
||||
// 'documents',
|
||||
];
|
||||
|
||||
/*
|
||||
@ -58,25 +63,21 @@ class RecurringInvoiceTransformer extends EntityTransformer
|
||||
|
||||
return $this->includeItem($invoice->client, $transformer, ENTITY_CLIENT);
|
||||
}
|
||||
|
||||
public function includeExpenses(Invoice $invoice)
|
||||
{
|
||||
$transformer = new ExpenseTransformer($this->account, $this->serializer);
|
||||
|
||||
return $this->includeCollection($invoice->expenses, $transformer, ENTITY_EXPENSE);
|
||||
}
|
||||
|
||||
public function includeDocuments(Invoice $invoice)
|
||||
{
|
||||
$transformer = new DocumentTransformer($this->account, $this->serializer);
|
||||
|
||||
$invoice->documents->each(function ($document) use ($invoice) {
|
||||
$document->setRelation('invoice', $invoice);
|
||||
});
|
||||
|
||||
return $this->includeCollection($invoice->documents, $transformer, ENTITY_DOCUMENT);
|
||||
}
|
||||
*/
|
||||
public function includeInvitations(RecurringInvoice $invoice)
|
||||
{
|
||||
$transformer = new RecurringInvoiceInvitationTransformer($this->serializer);
|
||||
|
||||
return $this->includeCollection($invoice->invitations, $transformer, RecurringInvoiceInvitation::class);
|
||||
}
|
||||
|
||||
public function includeDocuments(RecurringInvoice $invoice)
|
||||
{
|
||||
$transformer = new DocumentTransformer($this->serializer);
|
||||
|
||||
return $this->includeCollection($invoice->documents, $transformer, Document::class);
|
||||
}
|
||||
|
||||
public function transform(RecurringInvoice $invoice)
|
||||
{
|
||||
return [
|
||||
|
@ -76,6 +76,25 @@ class AddIsPublicToDocumentsTable extends Migration
|
||||
$table->enum('default_auto_bill', ['off', 'always', 'optin', 'optout'])->default('off');
|
||||
});
|
||||
|
||||
Schema::create('recurring_invoice_invitations', function ($t) {
|
||||
$t->increments('id');
|
||||
$t->unsignedInteger('company_id');
|
||||
$t->unsignedInteger('user_id');
|
||||
$t->unsignedInteger('client_contact_id');
|
||||
$t->unsignedInteger('recurring_invoice_id')->index();
|
||||
$t->string('key')->index();
|
||||
|
||||
$t->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
|
||||
$t->foreign('client_contact_id')->references('id')->on('client_contacts')->onDelete('cascade')->onUpdate('cascade');
|
||||
$t->foreign('recurring_invoice_id')->references('id')->on('recurring_invoices')->onDelete('cascade')->onUpdate('cascade');
|
||||
$t->foreign('company_id')->references('id')->on('companies')->onDelete('cascade')->onUpdate('cascade');
|
||||
|
||||
$t->timestamps(6);
|
||||
$t->softDeletes('deleted_at', 6);
|
||||
|
||||
$t->index(['deleted_at', 'recurring_invoice_id', 'company_id'], 'rec_co_del');
|
||||
$t->unique(['client_contact_id', 'recurring_invoice_id'], 'cli_rec');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user