Catch Quote Exceptions

This commit is contained in:
David Bomba 2023-06-26 21:05:15 +10:00
parent a37773b3a2
commit 2385bf8ad2
5 changed files with 74 additions and 20 deletions

View File

@ -165,9 +165,6 @@ class Rule extends BaseRule implements RuleInterface
$this->tax_rate1 = 0;
$this->tax_name1 = '';
// $this->tax_rate1 = $this->invoice->client->company->tax_data->regions->{$this->client_region}->subregions->{$this->client_subregion}->tax_rate;
// $this->tax_name1 = "Sales Tax";
return $this;
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Exceptions;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class QuoteConversion extends Exception
{
/**
* Report the exception.
*
* @return void
*/
public function report()
{
//
}
/**
* Render the exception into an HTTP response.
*
* @param Request $request
* @return Response
*/
public function render($request)
{
return response()->json(['message' => 'This quote has already been converted. Cannot convert again.'], 400);
}
}

View File

@ -182,7 +182,7 @@ class Import implements ShouldQueue
public function middleware()
{
return [(new WithoutOverlapping($this->user->account_id))];
return [(new WithoutOverlapping($this->company->company_key))];
}
/**

View File

@ -11,14 +11,14 @@
namespace App\Services\Quote;
use App\Events\Quote\QuoteWasApproved;
use App\Jobs\Entity\CreateEntityPdf;
use App\Jobs\Util\UnlinkFile;
use App\Models\Invoice;
use App\Models\Quote;
use App\Repositories\QuoteRepository;
use App\Utils\Ninja;
use App\Models\Quote;
use App\Jobs\Util\UnlinkFile;
use App\Utils\Traits\MakesHash;
use App\Exceptions\QuoteConversion;
use App\Jobs\Entity\CreateEntityPdf;
use App\Repositories\QuoteRepository;
use App\Events\Quote\QuoteWasApproved;
class QuoteService
{
@ -43,7 +43,7 @@ class QuoteService
public function convert() :self
{
if ($this->quote->invoice_id) {
return $this;
throw new QuoteConversion();
}
$convert_quote = (new ConvertQuote($this->quote->client))->run($this->quote);

View File

@ -11,16 +11,17 @@
namespace Tests\Feature;
use App\Models\ClientContact;
use App\Models\Project;
use App\Models\Quote;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Support\Facades\Session;
use Tests\MockAccountData;
use Tests\TestCase;
use App\Models\Quote;
use App\Models\Project;
use Tests\MockAccountData;
use App\Models\ClientContact;
use App\Utils\Traits\MakesHash;
use App\Exceptions\QuoteConversion;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Session;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Foundation\Testing\DatabaseTransactions;
/**
* @test
@ -32,6 +33,8 @@ class QuoteTest extends TestCase
use DatabaseTransactions;
use MockAccountData;
public $faker;
protected function setUp() :void
{
parent::setUp();
@ -49,6 +52,19 @@ class QuoteTest extends TestCase
);
}
public function testQuoteConversion()
{
$invoice = $this->quote->service()->convertToInvoice();
$this->assertInstanceOf('\App\Models\Invoice', $invoice);
$this->expectException(QuoteConversion::class);
$invoice = $this->quote->service()->convertToInvoice();
}
public function testQuoteDownloadPDF()
{
$i = $this->quote->invitations->first();