diff --git a/app/BulkActions/Sales/Invoices.php b/app/BulkActions/Sales/Invoices.php index 5dbcde98d..19a39e8bf 100644 --- a/app/BulkActions/Sales/Invoices.php +++ b/app/BulkActions/Sales/Invoices.php @@ -77,7 +77,7 @@ class Invoices extends BulkAction foreach ($invoices as $invoice) { $clone = $invoice->duplicate(); - event(new DocumentCreated($clone)); + event(new DocumentCreated($clone, $request)); } } diff --git a/app/Console/Commands/RecurringCheck.php b/app/Console/Commands/RecurringCheck.php index cc34ede2b..c50475905 100644 --- a/app/Console/Commands/RecurringCheck.php +++ b/app/Console/Commands/RecurringCheck.php @@ -135,7 +135,7 @@ class RecurringCheck extends Command switch ($type) { case 'App\Models\Document\Document': - event(new DocumentCreated($clone)); + event(new DocumentCreated($clone, request())); event(new DocumentRecurring($clone)); diff --git a/app/Jobs/Document/DuplicateDocument.php b/app/Jobs/Document/DuplicateDocument.php index 74b552382..498669cdb 100644 --- a/app/Jobs/Document/DuplicateDocument.php +++ b/app/Jobs/Document/DuplicateDocument.php @@ -33,7 +33,7 @@ class DuplicateDocument extends Job $this->clone = $this->document->duplicate(); }); - event(new DocumentCreated($this->clone)); + event(new DocumentCreated($this->clone, request())); return $this->clone; } diff --git a/app/Listeners/Document/SettingFieldCreated.php b/app/Listeners/Document/SettingFieldCreated.php index 33ae42885..66080152d 100644 --- a/app/Listeners/Document/SettingFieldCreated.php +++ b/app/Listeners/Document/SettingFieldCreated.php @@ -19,7 +19,7 @@ class SettingFieldCreated { $request = $event->request; - if ($request->has('setting')) { + if (!$request->has('setting')) { return; } diff --git a/app/Listeners/Document/SettingFieldUpdated.php b/app/Listeners/Document/SettingFieldUpdated.php index c28abdafd..50155cd8e 100644 --- a/app/Listeners/Document/SettingFieldUpdated.php +++ b/app/Listeners/Document/SettingFieldUpdated.php @@ -19,7 +19,7 @@ class SettingFieldUpdated { $request = $event->request; - if ($request->has('setting')) { + if (!$request->has('setting')) { return; } diff --git a/database/factories/Document.php b/database/factories/Document.php index 05aff0323..6a0123f3f 100644 --- a/database/factories/Document.php +++ b/database/factories/Document.php @@ -268,7 +268,7 @@ class Document extends AbstractFactory $init_status = $document->status; $document->status = 'draft'; - event(new DocumentCreated($document)); + event(new DocumentCreated($document, request())); $document->status = $init_status; $amount = $this->faker->randomFloat(2, 1, 1000); diff --git a/tests/Feature/Sales/InvoicesTest.php b/tests/Feature/Sales/InvoicesTest.php index 6c3531213..e58dd0052 100644 --- a/tests/Feature/Sales/InvoicesTest.php +++ b/tests/Feature/Sales/InvoicesTest.php @@ -39,6 +39,17 @@ class InvoicesTest extends FeatureTestCase ]); } + public function testItShouldDuplicateInvoice() + { + $invoice = $this->dispatch(new CreateDocument($this->getRequest())); + + $this->loginAs() + ->get(route('invoices.duplicate', ['invoice' => $invoice->id])) + ->assertStatus(302); + + $this->assertFlashLevel('success'); + } + public function testItShouldCreateInvoiceWithRecurring() { $request = $this->getRequest(true);