1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Recurring migration

This commit is contained in:
David Bomba 2020-10-05 22:32:56 +11:00
parent d3fdb57233
commit 45b6c1bcc2
3 changed files with 19 additions and 5 deletions

View File

@ -499,6 +499,9 @@ class Import implements ShouldQueue
$invoice_repository = new InvoiceMigrationRepository();
foreach ($data as $key => $resource) {
info("importing recurring with key {$key}");
$modified = $resource;
if (array_key_exists('client_id', $resource) && ! array_key_exists('clients', $this->ids)) {

View File

@ -11,11 +11,17 @@
namespace App\Models;
use App\Utils\Traits\Inviteable;
use App\Utils\Traits\MakesDates;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class RecurringInvoiceInvitation extends BaseModel
{
use MakesDates;
use SoftDeletes;
use Inviteable;
protected $fillable = ['client_contact_id'];
protected $touches = ['recurring_invoice'];

View File

@ -12,8 +12,11 @@
namespace App\Services\Recurring;
use App\Factory\InvoiceInvitationFactory;
use App\Factory\RecurringInvoiceFactory;
use App\Models\Invoice;
use App\Models\RecurringInvoice;
use App\Models\InvoiceInvitation;
use App\Models\RecurringInvoiceInvitation;
use App\Services\AbstractService;
use Illuminate\Support\Str;
@ -34,13 +37,14 @@ class CreateRecurringInvitations extends AbstractService
$this->entity = $entity;
$this->entity_name = lcfirst(Str::snake(class_basename($entity)));
$this->entity_id_name = $this->entity_name . "_id";
$this->invitation_class = Str::camel($this->entity_name);
$this->invitation_factory = $this->invitaiton_class . "Factory";
$this->invitation_class = 'App\Models\\' . ucfirst(Str::camel($this->entity_name)) . "Invitation";
$this->invitation_factory = 'App\Factory\\' . ucfirst(Str::camel($this->entity_name)) . "Factory";
}
public function run()
{
$this->entity->client->contacts->each(function ($contact) {
$invitation = $this->invitation_class::whereCompanyId($this->entity->company_id)
->whereClientContactId($contact->id)
->where($this->entity_id_name, $this->entity->id)
@ -49,14 +53,15 @@ class CreateRecurringInvitations extends AbstractService
if (! $invitation && $contact->send_email) {
$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->save();
} elseif ($invitation && ! $contact->send_email) {
$invitation->delete();
}
});
return $this->entity;
}
}
}