diff --git a/app/DataMapper/Tax/US/Rule.php b/app/DataMapper/Tax/US/Rule.php index fbfb5b78b323..59cd75943ca5 100644 --- a/app/DataMapper/Tax/US/Rule.php +++ b/app/DataMapper/Tax/US/Rule.php @@ -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; } diff --git a/app/Exceptions/QuoteConversion.php b/app/Exceptions/QuoteConversion.php new file mode 100644 index 000000000000..a4812f4c1bdb --- /dev/null +++ b/app/Exceptions/QuoteConversion.php @@ -0,0 +1,41 @@ +json(['message' => 'This quote has already been converted. Cannot convert again.'], 400); + } +} diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index b04d4c24670d..674b4e7c0579 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -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))]; } /** diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 56ab95d8eb38..fe6189106c47 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -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); diff --git a/tests/Feature/QuoteTest.php b/tests/Feature/QuoteTest.php index c324f05f8c30..320a4f1149d0 100644 --- a/tests/Feature/QuoteTest.php +++ b/tests/Feature/QuoteTest.php @@ -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();