mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Recurring migration
This commit is contained in:
parent
d3fdb57233
commit
45b6c1bcc2
@ -499,6 +499,9 @@ class Import implements ShouldQueue
|
|||||||
$invoice_repository = new InvoiceMigrationRepository();
|
$invoice_repository = new InvoiceMigrationRepository();
|
||||||
|
|
||||||
foreach ($data as $key => $resource) {
|
foreach ($data as $key => $resource) {
|
||||||
|
|
||||||
|
info("importing recurring with key {$key}");
|
||||||
|
|
||||||
$modified = $resource;
|
$modified = $resource;
|
||||||
|
|
||||||
if (array_key_exists('client_id', $resource) && ! array_key_exists('clients', $this->ids)) {
|
if (array_key_exists('client_id', $resource) && ! array_key_exists('clients', $this->ids)) {
|
||||||
|
@ -11,11 +11,17 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Utils\Traits\Inviteable;
|
||||||
|
use App\Utils\Traits\MakesDates;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
class RecurringInvoiceInvitation extends BaseModel
|
class RecurringInvoiceInvitation extends BaseModel
|
||||||
{
|
{
|
||||||
|
use MakesDates;
|
||||||
|
use SoftDeletes;
|
||||||
|
use Inviteable;
|
||||||
|
|
||||||
protected $fillable = ['client_contact_id'];
|
protected $fillable = ['client_contact_id'];
|
||||||
|
|
||||||
protected $touches = ['recurring_invoice'];
|
protected $touches = ['recurring_invoice'];
|
||||||
|
@ -12,8 +12,11 @@
|
|||||||
namespace App\Services\Recurring;
|
namespace App\Services\Recurring;
|
||||||
|
|
||||||
use App\Factory\InvoiceInvitationFactory;
|
use App\Factory\InvoiceInvitationFactory;
|
||||||
|
use App\Factory\RecurringInvoiceFactory;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
|
use App\Models\RecurringInvoice;
|
||||||
use App\Models\InvoiceInvitation;
|
use App\Models\InvoiceInvitation;
|
||||||
|
use App\Models\RecurringInvoiceInvitation;
|
||||||
use App\Services\AbstractService;
|
use App\Services\AbstractService;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
@ -34,13 +37,14 @@ class CreateRecurringInvitations extends AbstractService
|
|||||||
$this->entity = $entity;
|
$this->entity = $entity;
|
||||||
$this->entity_name = lcfirst(Str::snake(class_basename($entity)));
|
$this->entity_name = lcfirst(Str::snake(class_basename($entity)));
|
||||||
$this->entity_id_name = $this->entity_name . "_id";
|
$this->entity_id_name = $this->entity_name . "_id";
|
||||||
$this->invitation_class = Str::camel($this->entity_name);
|
$this->invitation_class = 'App\Models\\' . ucfirst(Str::camel($this->entity_name)) . "Invitation";
|
||||||
$this->invitation_factory = $this->invitaiton_class . "Factory";
|
$this->invitation_factory = 'App\Factory\\' . ucfirst(Str::camel($this->entity_name)) . "Factory";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$this->entity->client->contacts->each(function ($contact) {
|
$this->entity->client->contacts->each(function ($contact) {
|
||||||
|
|
||||||
$invitation = $this->invitation_class::whereCompanyId($this->entity->company_id)
|
$invitation = $this->invitation_class::whereCompanyId($this->entity->company_id)
|
||||||
->whereClientContactId($contact->id)
|
->whereClientContactId($contact->id)
|
||||||
->where($this->entity_id_name, $this->entity->id)
|
->where($this->entity_id_name, $this->entity->id)
|
||||||
@ -49,14 +53,15 @@ class CreateRecurringInvitations extends AbstractService
|
|||||||
|
|
||||||
if (! $invitation && $contact->send_email) {
|
if (! $invitation && $contact->send_email) {
|
||||||
$ii = $this->invitation_factory::create($this->entity->company_id, $this->entity->user_id);
|
$ii = $this->invitation_factory::create($this->entity->company_id, $this->entity->user_id);
|
||||||
$ii->{$this->entity_id} = $this->entity->id;
|
$ii->{$this->entity_id_name} = $this->entity->id;
|
||||||
$ii->client_contact_id = $contact->id;
|
$ii->client_contact_id = $contact->id;
|
||||||
$ii->save();
|
$ii->save();
|
||||||
} elseif ($invitation && ! $contact->send_email) {
|
} elseif ($invitation && ! $contact->send_email) {
|
||||||
$invitation->delete();
|
$invitation->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->entity;
|
return $this->entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user