mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 01:34:35 -04:00
Adjust credit balance on client record
This commit is contained in:
parent
77d489211e
commit
5070b2745e
@ -142,6 +142,7 @@ class CreditService
|
|||||||
$client = $this->credit->client->fresh();
|
$client = $this->credit->client->fresh();
|
||||||
$client->service()
|
$client->service()
|
||||||
->updatePaidToDate($adjustment)
|
->updatePaidToDate($adjustment)
|
||||||
|
->adjustCreditBalance($adjustment * -1)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
event('eloquent.created: App\Models\Payment', $payment);
|
event('eloquent.created: App\Models\Payment', $payment);
|
||||||
|
@ -45,6 +45,11 @@ class MarkSent
|
|||||||
->touchPdf()
|
->touchPdf()
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
$this->client
|
||||||
|
->service()
|
||||||
|
->adjustCreditBalance($this->credit->amount)
|
||||||
|
->save();
|
||||||
|
|
||||||
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||||
|
|
||||||
return $this->credit;
|
return $this->credit;
|
||||||
|
@ -13,11 +13,13 @@ namespace Tests\Feature;
|
|||||||
|
|
||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use App\DataMapper\DefaultSettings;
|
use App\DataMapper\DefaultSettings;
|
||||||
|
use App\Factory\InvoiceItemFactory;
|
||||||
use App\Models\Account;
|
use App\Models\Account;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\CompanyToken;
|
use App\Models\CompanyToken;
|
||||||
|
use App\Models\Credit;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@ -61,6 +63,72 @@ class ClientTest extends TestCase
|
|||||||
$this->makeTestData();
|
$this->makeTestData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildLineItems()
|
||||||
|
{
|
||||||
|
$line_items = [];
|
||||||
|
|
||||||
|
$item = InvoiceItemFactory::create();
|
||||||
|
$item->quantity = 1;
|
||||||
|
$item->cost = 10;
|
||||||
|
|
||||||
|
$line_items[] = $item;
|
||||||
|
|
||||||
|
$item = InvoiceItemFactory::create();
|
||||||
|
$item->quantity = 1;
|
||||||
|
$item->cost = 10;
|
||||||
|
|
||||||
|
$line_items[] = $item;
|
||||||
|
|
||||||
|
return $line_items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreditBalance()
|
||||||
|
{
|
||||||
|
$this->client->credit_balance = 0;
|
||||||
|
$this->client->save();
|
||||||
|
|
||||||
|
$this->assertEquals(0, $this->client->credit_balance);
|
||||||
|
|
||||||
|
$credit = [
|
||||||
|
'status_id' => 1,
|
||||||
|
'number' => 'dfdfd',
|
||||||
|
'discount' => 0,
|
||||||
|
'is_amount_discount' => 1,
|
||||||
|
'number' => '34343xx43',
|
||||||
|
'public_notes' => 'notes',
|
||||||
|
'is_deleted' => 0,
|
||||||
|
'custom_value1' => 0,
|
||||||
|
'custom_value2' => 0,
|
||||||
|
'custom_value3' => 0,
|
||||||
|
'custom_value4' => 0,
|
||||||
|
'status' => 1,
|
||||||
|
'client_id' => $this->encodePrimaryKey($this->client->id),
|
||||||
|
'line_items' => $this->buildLineItems()
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/credits/', $credit)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$credit_id = $arr['data']['id'];
|
||||||
|
|
||||||
|
$credit = Credit::find($this->decodePrimaryKey($credit_id));
|
||||||
|
|
||||||
|
$this->assertNotNull($credit);
|
||||||
|
|
||||||
|
$this->assertEquals(0, $credit->balance);
|
||||||
|
|
||||||
|
$credit->service()->markSent()->save();
|
||||||
|
|
||||||
|
$this->assertEquals(20, $credit->balance);
|
||||||
|
$this->assertEquals(20, $credit->client->fresh()->credit_balance);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testStoreClientUsingCountryCode()
|
public function testStoreClientUsingCountryCode()
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user