1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
This commit is contained in:
David Bomba 2019-05-15 19:20:52 +10:00
parent b365d8dc6e
commit 92b46d5ed8
4 changed files with 57 additions and 11 deletions

View File

@ -11,6 +11,8 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Events\Invoice\InvoiceWasCreated;
use App\Events\Invoice\InvoiceWasUpdated;
use App\Factory\CloneInvoiceFactory; use App\Factory\CloneInvoiceFactory;
use App\Factory\CloneInvoiceToQuoteFactory; use App\Factory\CloneInvoiceToQuoteFactory;
use App\Factory\InvoiceFactory; use App\Factory\InvoiceFactory;
@ -114,6 +116,8 @@ class InvoiceController extends BaseController
$invoice = StoreInvoice::dispatchNow($invoice, $request->all()); //todo potentially this may return mixed ie PDF/$invoice... need to revisit when we implement UI $invoice = StoreInvoice::dispatchNow($invoice, $request->all()); //todo potentially this may return mixed ie PDF/$invoice... need to revisit when we implement UI
event(new InvoiceWasCreated($invoice));
return $this->itemResponse($invoice); return $this->itemResponse($invoice);
} }
@ -161,6 +165,8 @@ class InvoiceController extends BaseController
$invoice = $this->invoice_repo->save($request->all(), $invoice); $invoice = $this->invoice_repo->save($request->all(), $invoice);
event(new InvoiceWasUpdated($invoice));
return $this->itemResponse($invoice); return $this->itemResponse($invoice);
} }

View File

@ -13,8 +13,9 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class Activity extends BaseModel class Activity extends Model
{ {
const CREATE_CLIENT=1; const CREATE_CLIENT=1;
const ARCHIVE_CLIENT=2; const ARCHIVE_CLIENT=2;
const DELETE_CLIENT=3; const DELETE_CLIENT=3;

View File

@ -44,11 +44,6 @@ class InvoiceRepository extends BaseRepository
*/ */
public function save($data, Invoice $invoice) : ?Invoice public function save($data, Invoice $invoice) : ?Invoice
{ {
/* Test if this is a new invoice or existing */
$new_invoice = true;
if(isset($invoice->id))
$new_invoice = false;
/* Always carry forward the initial invoice amount this is important for tracking client balance changes later......*/ /* Always carry forward the initial invoice amount this is important for tracking client balance changes later......*/
$starting_amount = $invoice->amount; $starting_amount = $invoice->amount;
@ -63,11 +58,6 @@ class InvoiceRepository extends BaseRepository
$invoice->save(); $invoice->save();
if($new_invoice)
event(new InvoiceWasCreated($invoice));
else
event(new InvoiceWasUpdated($invoice));
$finished_amount = $invoice->amount; $finished_amount = $invoice->amount;
if($finished_amount != $starting_amount) if($finished_amount != $starting_amount)

View File

@ -0,0 +1,49 @@
<?php
namespace Tests\Integration;
use App\Events\Invoice\InvoiceWasCreated;
use App\Events\Invoice\InvoiceWasUpdated;
use App\Jobs\Invoice\MarkPaid;
use App\Models\Account;
use App\Models\Activity;
use App\Models\Company;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\User;
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
* @covers App\Jobs\Company\UpdateCompanyLedgerWithInvoice
*/
class UpdateCompanyLedgerInvoiceTest extends TestCase
{
use MockAccountData;
use DatabaseTransactions;
public function setUp() :void
{
parent::setUp();
$this->makeTestData();
}
public function testUpdatedInvoiceEventFires()
{
$this->invoice->status_id = Invoice::STATUS_PAID;
$this->invoice->save();
// $this->expectsEvents(InvoiceWasUpdated::class);
$activities = Activity::whereInvoiceId($this->invoice->id)->get();
$this->assertEquals(count($activities), 1);
}
}