Fixes for recurring migratoin

This commit is contained in:
David Bomba 2020-10-06 11:52:16 +11:00
parent 1264486bb9
commit 484b28d3ce
6 changed files with 33 additions and 46 deletions

View File

@ -53,7 +53,7 @@ class QueryLogging
Log::info($request->method().' - '.$request->url().": $count queries - ".$time);
// if($count > 50)
// Log::info($queries);
Log::info($queries);
}
}

View File

@ -99,14 +99,14 @@ class Import implements ShouldQueue
'payment_terms',
'tax_rates',
'clients',
// 'products',
// 'invoices',
'products',
'invoices',
'recurring_invoices',
// 'quotes',
// 'payments',
// 'credits',
// 'company_gateways',
// 'client_gateway_tokens',
'quotes',
'payments',
'credits',
'company_gateways',
'client_gateway_tokens',
// //'documents',
];

View File

@ -84,8 +84,6 @@ class InvoiceMigrationRepository extends BaseRepository
$this->saveDocuments($data['documents'], $model);
}
info(sprintf('App\\Factory\\%sInvitationFactory', $resource));
$invitation_factory_class = sprintf('App\\Factory\\%sInvitationFactory', $resource);
if (isset($data['client_contacts'])) {
@ -134,20 +132,16 @@ class InvoiceMigrationRepository extends BaseRepository
$model->service()->createInvitations();
}
info("saving 3a");
$model = $model->calc()->getInvoice();
info("saving 3b");
$state['finished_amount'] = $model->amount;
$model = $model->service()->applyNumber()->save();
info("saving 3c");
if ($model->company->update_products !== false) {
UpdateOrCreateProduct::dispatch($model->line_items, $model, $model->company);
}
info("saving 4");
if ($class->name == Invoice::class || $class->name == RecurringInvoice::class) {
if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) {
@ -177,7 +171,7 @@ info("saving 4");
}
$model->save();
info("saving 5");
return $model->fresh();
}
}

View File

@ -44,7 +44,7 @@ class ApplyNumber extends AbstractService
break;
default:
// code...
$this->recurring_entity->number = $this->getNextRecurringInvoiceNumber($this->client);
break;
}

View File

@ -43,38 +43,31 @@ class CreateRecurringInvitations extends AbstractService
public function run()
{
info($this->entity_name);
info($this->entity_id_name);
info($this->invitation_class);
info($this->invitation_factory);
try {
$this->entity->client->contacts->each(function ($contact) {
try {
$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)
->withTrashed()
->first();
$invitation = $this->invitation_class::whereCompanyId($this->entity->company_id)
->whereClientContactId($contact->id)
->where($this->entity_id_name, $this->entity->id)
->withTrashed()
->first();
if (! $invitation && $contact->send_email) {
$ii = $this->invitation_factory::create($this->entity->company_id, $this->entity->user_id);
$ii->{$this->entity_id_name} = $this->entity->id;
$ii->client_contact_id = $contact->id;
$ii->save();
} elseif ($invitation && ! $contact->send_email) {
$invitation->delete();
}
if (! $invitation && $contact->send_email) {
$ii = $this->invitation_factory::create($this->entity->company_id, $this->entity->user_id);
$ii->{$this->entity_id_name} = $this->entity->id;
$ii->client_contact_id = $contact->id;
$ii->save();
} elseif ($invitation && ! $contact->send_email) {
$invitation->delete();
}
});
}
catch(\Exception $e)
{
info($e->getMessage());
}
info("returning the entity");
});
}
catch(\Exception $e)
{
info($e->getMessage());
}
return $this->entity;
}

View File

@ -167,7 +167,7 @@ trait GeneratesCounter
//Return a valid counter
$pattern = '';
$padding = $client->getSetting('counter_padding');
$invoice_number = $this->checkEntityNumber(Invoice::class, $client, $counter, $padding, $pattern);
$invoice_number = $this->checkEntityNumber(RecurringInvoice::class, $client, $counter, $padding, $pattern);
$invoice_number = $this->prefixCounter($invoice_number, $client->getSetting('recurring_number_prefix'));
//increment the correct invoice_number Counter (company vs client)