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); Log::info($request->method().' - '.$request->url().": $count queries - ".$time);
// if($count > 50) // if($count > 50)
// Log::info($queries); Log::info($queries);
} }
} }

View File

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

View File

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

View File

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

View File

@ -43,38 +43,31 @@ class CreateRecurringInvitations extends AbstractService
public function run() public function run()
{ {
info($this->entity_name);
info($this->entity_id_name);
info($this->invitation_class);
info($this->invitation_factory);
try { try {
$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)
->withTrashed() ->withTrashed()
->first(); ->first();
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_name} = $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();
} }
}); });
} }
catch(\Exception $e) catch(\Exception $e)
{ {
info($e->getMessage()); info($e->getMessage());
} }
info("returning the entity");
return $this->entity; return $this->entity;
} }

View File

@ -167,7 +167,7 @@ trait GeneratesCounter
//Return a valid counter //Return a valid counter
$pattern = ''; $pattern = '';
$padding = $client->getSetting('counter_padding'); $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')); $invoice_number = $this->prefixCounter($invoice_number, $client->getSetting('recurring_number_prefix'));
//increment the correct invoice_number Counter (company vs client) //increment the correct invoice_number Counter (company vs client)