mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Merge pull request #8151 from turbo124/v5-develop
Fixes for deleting payments
This commit is contained in:
commit
7768f714e1
@ -56,7 +56,7 @@ class ReactBuilder extends Command
|
||||
$directoryIterator = new \RecursiveDirectoryIterator(public_path('react'), \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
|
||||
foreach (new \RecursiveIteratorIterator($directoryIterator) as $file) {
|
||||
if (str_contains($file->getFileName(), '.js')) {
|
||||
if (str_contains($file->getFileName(), '.js') && !strpos($file->getFileName(), '.json')) {
|
||||
if (str_contains($file->getFileName(), 'index.')) {
|
||||
$includes .= '<script type="module" crossorigin src="/react/'.$file->getFileName().'"></script>'."\n";
|
||||
} else {
|
||||
|
@ -181,6 +181,11 @@ class ClientContact extends Authenticatable implements HasLocalePreference
|
||||
return $this->hasMany(InvoiceInvitation::class);
|
||||
}
|
||||
|
||||
public function recurring_invoice_invitations()
|
||||
{
|
||||
return $this->hasMany(RecurringInvoiceInvitation::class);
|
||||
}
|
||||
|
||||
public function quote_invitations()
|
||||
{
|
||||
return $this->hasMany(QuoteInvitation::class);
|
||||
|
@ -48,6 +48,7 @@ class ClientContactObserver
|
||||
$clientContact->invoice_invitations()->delete();
|
||||
$clientContact->quote_invitations()->delete();
|
||||
$clientContact->credit_invitations()->delete();
|
||||
$clientContact->recurring_invoice_invitations()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,9 +59,9 @@ class ClientContactObserver
|
||||
*/
|
||||
public function restored(ClientContact $clientContact)
|
||||
{
|
||||
$clientContact->invoice_invitations()->restore();
|
||||
$clientContact->quote_invitations()->restore();
|
||||
$clientContact->credit_invitations()->restore();
|
||||
// $clientContact->invoice_invitations()->restore();
|
||||
// $clientContact->quote_invitations()->restore();
|
||||
// $clientContact->credit_invitations()->restore();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -225,6 +225,7 @@ use App\Listeners\User\UpdateUserLastLogin;
|
||||
use App\Listeners\User\UpdatedUserActivity;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\CompanyToken;
|
||||
@ -241,6 +242,7 @@ use App\Models\Subscription;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
use App\Observers\AccountObserver;
|
||||
use App\Observers\ClientContactObserver;
|
||||
use App\Observers\ClientObserver;
|
||||
use App\Observers\CompanyGatewayObserver;
|
||||
use App\Observers\CompanyObserver;
|
||||
@ -633,6 +635,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
Account::observe(AccountObserver::class);
|
||||
Subscription::observe(SubscriptionObserver::class);
|
||||
Client::observe(ClientObserver::class);
|
||||
ClientContact::observe(ClientContactObserver::class);
|
||||
Company::observe(CompanyObserver::class);
|
||||
CompanyGateway::observe(CompanyGatewayObserver::class);
|
||||
CompanyToken::observe(CompanyTokenObserver::class);
|
||||
|
@ -257,7 +257,8 @@ class PaymentRepository extends BaseRepository {
|
||||
|
||||
$payment = $payment->service()->deletePayment();
|
||||
|
||||
event(new PaymentWasDeleted($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
if($payment)
|
||||
event(new PaymentWasDeleted($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
return $payment;
|
||||
|
||||
|
@ -37,7 +37,7 @@ class ClientService
|
||||
$this->client->balance += $amount;
|
||||
$this->client->save();
|
||||
|
||||
}, 2);
|
||||
}, 1);
|
||||
}
|
||||
catch (\Throwable $throwable) {
|
||||
nlog("DB ERROR " . $throwable->getMessage());
|
||||
@ -58,7 +58,7 @@ class ClientService
|
||||
$this->client->paid_to_date += $paid_to_date;
|
||||
$this->client->save();
|
||||
|
||||
}, 2);
|
||||
}, 1);
|
||||
}
|
||||
catch (\Throwable $throwable) {
|
||||
nlog("DB ERROR " . $throwable->getMessage());
|
||||
@ -79,7 +79,7 @@ class ClientService
|
||||
$this->client->paid_to_date += $amount;
|
||||
$this->client->save();
|
||||
|
||||
}, 2);
|
||||
}, 1);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -38,22 +38,21 @@ class DeletePayment
|
||||
|
||||
\DB::connection(config('database.default'))->transaction(function () {
|
||||
|
||||
|
||||
if ($this->payment->is_deleted) {
|
||||
return $this->payment;
|
||||
}
|
||||
|
||||
$this->payment = Payment::withTrashed()->where('id', $this->payment->id)->lockForUpdate()->first();
|
||||
|
||||
$this->setStatus(Payment::STATUS_CANCELLED) //sets status of payment
|
||||
->updateCreditables() //return the credits first
|
||||
->adjustInvoices()
|
||||
->deletePaymentables()
|
||||
->cleanupPayment()
|
||||
->save();
|
||||
if (!$this->payment->is_deleted) {
|
||||
|
||||
$this->setStatus(Payment::STATUS_CANCELLED) //sets status of payment
|
||||
->updateCreditables() //return the credits first
|
||||
->adjustInvoices()
|
||||
->deletePaymentables()
|
||||
->cleanupPayment()
|
||||
->save();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}, 2);
|
||||
}, 1);
|
||||
|
||||
return $this->payment;
|
||||
|
||||
|
@ -1,148 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Scheduler;
|
||||
|
||||
use App\Export\CSV\ClientExport;
|
||||
use App\Models\Scheduler;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\MockUnitData;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SchedulerTest extends TestCase
|
||||
{
|
||||
use MakesHash;
|
||||
use MockUnitData;
|
||||
use WithoutEvents;
|
||||
// use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Session::start();
|
||||
|
||||
$this->faker = \Faker\Factory::create();
|
||||
|
||||
Model::reguard();
|
||||
|
||||
$this->makeTestData();
|
||||
|
||||
$this->withoutMiddleware(
|
||||
ThrottleRequests::class
|
||||
);
|
||||
|
||||
// $this->withoutExceptionHandling();
|
||||
}
|
||||
|
||||
public function testSchedulerCantBeCreatedWithWrongData()
|
||||
{
|
||||
$data = [
|
||||
'repeat_every' => Scheduler::DAILY,
|
||||
'job' => Scheduler::CREATE_CLIENT_REPORT,
|
||||
'date_key' => '123',
|
||||
'report_keys' => ['test'],
|
||||
'date_range' => 'all',
|
||||
// 'start_from' => '2022-01-01'
|
||||
];
|
||||
|
||||
$response = false;
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/task_scheduler/', $data);
|
||||
|
||||
$response->assertSessionHasErrors();
|
||||
}
|
||||
|
||||
public function testSchedulerCanBeUpdated()
|
||||
{
|
||||
$response = $this->createScheduler();
|
||||
|
||||
$arr = $response->json();
|
||||
$id = $arr['data']['id'];
|
||||
|
||||
$scheduler = Scheduler::find($this->decodePrimaryKey($id));
|
||||
|
||||
$updateData = [
|
||||
'start_from' => 1655934741,
|
||||
];
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/task_scheduler/'.$this->encodePrimaryKey($scheduler->id), $updateData);
|
||||
|
||||
$responseData = $response->json();
|
||||
$this->assertEquals($updateData['start_from'], $responseData['data']['start_from']);
|
||||
}
|
||||
|
||||
public function testSchedulerCanBeSeen()
|
||||
{
|
||||
$response = $this->createScheduler();
|
||||
|
||||
$arr = $response->json();
|
||||
$id = $arr['data']['id'];
|
||||
|
||||
$scheduler = Scheduler::find($this->decodePrimaryKey($id));
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/task_scheduler/'.$this->encodePrimaryKey($scheduler->id));
|
||||
|
||||
$arr = $response->json();
|
||||
$this->assertEquals('create_client_report', $arr['data']['action_name']);
|
||||
}
|
||||
|
||||
public function testSchedulerJobCanBeUpdated()
|
||||
{
|
||||
$response = $this->createScheduler();
|
||||
|
||||
$arr = $response->json();
|
||||
$id = $arr['data']['id'];
|
||||
|
||||
$scheduler = Scheduler::find($this->decodePrimaryKey($id));
|
||||
|
||||
$this->assertSame('create_client_report', $scheduler->action_name);
|
||||
|
||||
$updateData = [
|
||||
'job' => Scheduler::CREATE_CREDIT_REPORT,
|
||||
'date_range' => 'all',
|
||||
'report_keys' => ['test1'],
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/task_scheduler/'.$this->encodePrimaryKey($scheduler->id), $updateData);
|
||||
|
||||
$updatedSchedulerJob = Scheduler::first()->action_name;
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertSame('create_credit_report', $arr['data']['action_name']);
|
||||
}
|
||||
|
||||
public function createScheduler()
|
||||
{
|
||||
$data = [
|
||||
'repeat_every' => Scheduler::DAILY,
|
||||
'job' => Scheduler::CREATE_CLIENT_REPORT,
|
||||
'date_key' => '123',
|
||||
'report_keys' => ['test'],
|
||||
'date_range' => 'all',
|
||||
'start_from' => '2022-01-01',
|
||||
];
|
||||
|
||||
return $response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/task_scheduler/', $data);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user