Fixes for a race condition affecting autobilling

This commit is contained in:
David Bomba 2021-12-03 17:19:24 +11:00
parent a63b02f77b
commit 4b2417f44e
7 changed files with 7 additions and 18 deletions

View File

@ -53,7 +53,7 @@ class AutoBill
nlog("autobill {$this->invoice->id}"); nlog("autobill {$this->invoice->id}");
$this->invoice->service()->autoBill()->save(); $this->invoice->service()->autoBill();
} }
catch(\Exception $e) { catch(\Exception $e) {

View File

@ -145,7 +145,7 @@ class SendRecurring implements ShouldQueue
if ($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $invoice->auto_bill_enabled) { if ($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $invoice->auto_bill_enabled) {
nlog("attempting to autobill {$invoice->number}"); nlog("attempting to autobill {$invoice->number}");
$invoice->service()->autoBill()->save(); $invoice->service()->autoBill();
} }
elseif($invoice->client->getSetting('auto_bill_date') == 'on_due_date' && $invoice->auto_bill_enabled) { elseif($invoice->client->getSetting('auto_bill_date') == 'on_due_date' && $invoice->auto_bill_enabled) {
@ -153,7 +153,7 @@ class SendRecurring implements ShouldQueue
if($invoice->due_date && Carbon::parse($invoice->due_date)->startOfDay()->lte(now()->startOfDay())) { if($invoice->due_date && Carbon::parse($invoice->due_date)->startOfDay()->lte(now()->startOfDay())) {
nlog("attempting to autobill {$invoice->number}"); nlog("attempting to autobill {$invoice->number}");
$invoice->service()->autoBill()->save(); $invoice->service()->autoBill();
} }

View File

@ -36,17 +36,6 @@ class TriggeredActions extends AbstractService
public function run() public function run()
{ {
// if ($this->request->has('auto_bill') && $this->request->input('auto_bill') == 'true') {
// $this->credit = $this->credit->service()->autoBill()->save();
// }
// if ($this->request->has('paid') && $this->request->input('paid') == 'true') {
// $this->credit = $this->credit->service()->markPaid()->save();
// }
// if ($this->request->has('amount_paid') && is_numeric($this->request->input('amount_paid')) ) {
// $this->credit = $this->credit->service()->applyPaymentAmount($this->request->input('amount_paid'))->save();
// }
if ($this->request->has('send_email') && $this->request->input('send_email') == 'true') { if ($this->request->has('send_email') && $this->request->input('send_email') == 'true') {
$this->sendEmail(); $this->sendEmail();

View File

@ -130,7 +130,7 @@ class AutoBillInvoice extends AbstractService
info("Auto Bill payment captured for ".$this->invoice->number); info("Auto Bill payment captured for ".$this->invoice->number);
} }
return $this->invoice->fresh(); // return $this->invoice->fresh();
} }
/** /**

View File

@ -246,7 +246,7 @@ class InvoiceService
public function autoBill() public function autoBill()
{ {
$this->invoice = (new AutoBillInvoice($this->invoice, $this->invoice->company->db))->run(); (new AutoBillInvoice($this->invoice, $this->invoice->company->db))->run();
return $this; return $this;
} }

View File

@ -37,7 +37,7 @@ class TriggeredActions extends AbstractService
public function run() public function run()
{ {
if ($this->request->has('auto_bill') && $this->request->input('auto_bill') == 'true') { if ($this->request->has('auto_bill') && $this->request->input('auto_bill') == 'true') {
$this->invoice = $this->invoice->service()->autoBill()->save(); $this->invoice = $this->invoice->service()->autoBill();
} }
if ($this->request->has('paid') && $this->request->input('paid') == 'true') { if ($this->request->has('paid') && $this->request->input('paid') == 'true') {

View File

@ -38,7 +38,7 @@ class AutoBillInvoiceTest extends TestCase
$this->assertEquals($this->client->paid_to_date, 0); $this->assertEquals($this->client->paid_to_date, 0);
$this->assertEquals($this->client->credit_balance, 10); $this->assertEquals($this->client->credit_balance, 10);
$this->invoice->service()->markSent()->autoBill()->save(); $this->invoice->service()->markSent()->autoBill();
$this->assertNotNull($this->invoice->payments()); $this->assertNotNull($this->invoice->payments());
$this->assertEquals(10, $this->invoice->payments()->sum('payments.amount')); $this->assertEquals(10, $this->invoice->payments()->sum('payments.amount'));