1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Pass references instead of full models into auto bill jobs

This commit is contained in:
David Bomba 2022-10-28 12:10:20 +11:00
parent c05a0dd598
commit 08dbbade14
7 changed files with 31 additions and 26 deletions

View File

@ -56,10 +56,10 @@ class Kernel extends ConsoleKernel
$schedule->job(new QueueSize)->everyFiveMinutes()->withoutOverlapping();
/* Checks for large companies and marked them as is_large */
$schedule->job(new CompanySizeCheck)->daily()->withoutOverlapping();
$schedule->job(new CompanySizeCheck)->dailyAt('23:20')->withoutOverlapping();
/* Pulls in the latest exchange rates */
$schedule->job(new UpdateExchangeRates)->daily()->withoutOverlapping();
$schedule->job(new UpdateExchangeRates)->dailyAt('23:30')->withoutOverlapping();
/* Runs cleanup code for subscriptions */
$schedule->job(new SubscriptionCron)->daily()->withoutOverlapping();

View File

@ -141,7 +141,7 @@ class SwissQrGenerator
// Optionally, add some human-readable information about what the bill is for.
$qrBill->setAdditionalInformation(
QrBill\DataGroup\Element\AdditionalInformation::create(
$this->invoice->public_notes ?: ''
$this->invoice->public_notes ?: ctrans('texts.invoice_number_placeholder', ['invoice' => $invoice_number])
)
);
@ -149,7 +149,7 @@ class SwissQrGenerator
// Now get the QR code image and save it as a file.
try {
$output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, 'en');
$output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, $this->client->locale() ?: 'en');
$html = $output
->setPrintable(false)

View File

@ -25,7 +25,7 @@ class AutoBill implements ShouldQueue
public $tries = 1;
public Invoice $invoice;
public int $invoice_id;
public string $db;
@ -34,9 +34,9 @@ class AutoBill implements ShouldQueue
*
* @return void
*/
public function __construct(Invoice $invoice, ?string $db)
public function __construct(int $invoice_id, ?string $db)
{
$this->invoice = $invoice;
$this->invoice_id = $invoice_id;
$this->db = $db;
}
@ -54,11 +54,13 @@ class AutoBill implements ShouldQueue
}
try {
nlog("autobill {$this->invoice->id}");
nlog("autobill {$this->invoice_id}");
$invoice = Invoice::withTrashed()->find($this->invoice_id);
$this->invoice->service()->autoBill();
$invoice->service()->autoBill();
} catch (\Exception $e) {
nlog("Failed to capture payment for {$this->invoice->company_id} - {$this->invoice->number} ->".$e->getMessage());
nlog("Failed to capture payment for {$this->invoice_id} ->".$e->getMessage());
}
}
}

View File

@ -58,13 +58,12 @@ class AutoBillCron
->whereHas('company', function ($query) {
$query->where('is_disabled', 0);
})
->orderBy('id', 'DESC')
->with('company');
->orderBy('id', 'DESC');
nlog($auto_bill_partial_invoices->count().' partial invoices to auto bill');
$auto_bill_partial_invoices->cursor()->each(function ($invoice) {
AutoBill::dispatch($invoice, false);
AutoBill::dispatch($invoice->id, false);
});
$auto_bill_invoices = Invoice::whereDate('due_date', '<=', now())
@ -76,13 +75,12 @@ class AutoBillCron
->whereHas('company', function ($query) {
$query->where('is_disabled', 0);
})
->orderBy('id', 'DESC')
->with('company');
->orderBy('id', 'DESC');
nlog($auto_bill_invoices->count().' full invoices to auto bill');
$auto_bill_invoices->cursor()->each(function ($invoice) {
AutoBill::dispatch($invoice, false);
AutoBill::dispatch($invoice->id, false);
});
} else {
//multiDB environment, need to
@ -98,13 +96,12 @@ class AutoBillCron
->whereHas('company', function ($query) {
$query->where('is_disabled', 0);
})
->orderBy('id', 'DESC')
->with('company');
->orderBy('id', 'DESC');
nlog($auto_bill_partial_invoices->count()." partial invoices to auto bill db = {$db}");
$auto_bill_partial_invoices->cursor()->each(function ($invoice) use ($db) {
AutoBill::dispatch($invoice, $db);
AutoBill::dispatch($invoice->id, $db);
});
$auto_bill_invoices = Invoice::whereDate('due_date', '<=', now())
@ -116,14 +113,13 @@ class AutoBillCron
->whereHas('company', function ($query) {
$query->where('is_disabled', 0);
})
->orderBy('id', 'DESC')
->with('company');
->orderBy('id', 'DESC');
nlog($auto_bill_invoices->count()." full invoices to auto bill db = {$db}");
$auto_bill_invoices->cursor()->each(function ($invoice) use ($db) {
nlog($this->counter);
AutoBill::dispatch($invoice, $db);
AutoBill::dispatch($invoice->id, $db);
$this->counter++;
});
}

View File

@ -130,7 +130,7 @@ class SendRecurring implements ShouldQueue
$invoice->invitations->each(function ($invitation) use ($invoice) {
if ($invitation->contact && ! $invitation->contact->trashed() && strlen($invitation->contact->email) >= 1 && $invoice->client->getSetting('auto_email_invoice')) {
try {
EmailEntity::dispatch($invitation, $invoice->company)->delay(rand(10,20));
EmailEntity::dispatch($invitation, $invoice->company)->delay(rand(1,2));
} catch (\Exception $e) {
nlog($e->getMessage());
}
@ -143,13 +143,13 @@ class SendRecurring implements ShouldQueue
if ($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $invoice->auto_bill_enabled) {
nlog("attempting to autobill {$invoice->number}");
// $invoice->service()->autoBill();
AutoBill::dispatch($invoice, $this->db)->delay(rand(30,40));
AutoBill::dispatch($invoice->id, $this->db)->delay(rand(1,2));
} elseif ($invoice->client->getSetting('auto_bill_date') == 'on_due_date' && $invoice->auto_bill_enabled) {
if ($invoice->due_date && Carbon::parse($invoice->due_date)->startOfDay()->lte(now()->startOfDay())) {
nlog("attempting to autobill {$invoice->number}");
// $invoice->service()->autoBill();
AutoBill::dispatch($invoice, $this->db)->delay(rand(30,40));
AutoBill::dispatch($invoice->id, $this->db)->delay(rand(1,2));
}
}
}

View File

@ -99,7 +99,7 @@ class ReminderJob implements ShouldQueue
(Ninja::isSelfHost() || $invoice->company->account->isPaidHostedClient())) {
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
EmailEntity::dispatchSync($invitation, $invitation->company, $reminder_template);
nlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}");
});

View File

@ -33,6 +33,13 @@
margin: 0;
padding: 0;
}
#qr-bill {
width:100% !important;
box-sizing: border-box;
border-collapse: collapse;
color: #000;
}
.header-container {
display: grid;