2019-05-16 07:36:53 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Integration;
|
|
|
|
|
|
|
|
use App\Events\Invoice\InvoiceWasCreated;
|
|
|
|
use App\Events\Invoice\InvoiceWasUpdated;
|
|
|
|
use App\Events\Payment\PaymentWasCreated;
|
2019-05-16 08:00:27 +02:00
|
|
|
use App\Jobs\Invoice\MarkInvoicePaid;
|
2019-05-16 07:36:53 +02:00
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Activity;
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\CompanyLedger;
|
|
|
|
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;
|
|
|
|
|
2020-03-28 04:45:11 +01:00
|
|
|
/** @test*/
|
2020-02-20 22:05:01 +01:00
|
|
|
|
2019-05-16 07:36:53 +02:00
|
|
|
class UpdateCompanyLedgerTest extends TestCase
|
|
|
|
{
|
|
|
|
use MockAccountData;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function testPaymentIsPresentInLedger()
|
|
|
|
{
|
2020-02-04 08:51:44 +01:00
|
|
|
$invoice = $this->invoice->service()->markPaid()->save();
|
2019-05-16 07:36:53 +02:00
|
|
|
|
|
|
|
$ledger = CompanyLedger::whereClientId($invoice->client_id)
|
|
|
|
->whereCompanyId($invoice->company_id)
|
|
|
|
->orderBy('id', 'DESC')
|
|
|
|
->first();
|
|
|
|
|
2019-12-29 07:28:57 +01:00
|
|
|
$payment = $ledger->adjustment * - 1;
|
2019-05-16 07:36:53 +02:00
|
|
|
$this->assertEquals($invoice->amount, $payment);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function testInvoiceIsPresentInLedger()
|
|
|
|
{
|
2019-10-11 02:26:35 +02:00
|
|
|
//$this->invoice->save();
|
2019-05-16 07:36:53 +02:00
|
|
|
|
|
|
|
$ledger = CompanyLedger::whereCompanyLedgerableId($this->invoice->id)
|
|
|
|
->whereCompanyLedgerableType(Invoice::class)
|
2019-10-11 02:26:35 +02:00
|
|
|
->whereCompanyId($this->invoice->company_id)
|
2019-05-16 07:36:53 +02:00
|
|
|
->get();
|
|
|
|
|
2019-12-29 07:28:57 +01:00
|
|
|
$this->assertGreaterThan(1, count($ledger));
|
2019-05-16 07:36:53 +02:00
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|