diff --git a/app/Factory/CloneQuoteToInvoiceFactory.php b/app/Factory/CloneQuoteToInvoiceFactory.php index b04b8104253d..4b0eb4f91e62 100644 --- a/app/Factory/CloneQuoteToInvoiceFactory.php +++ b/app/Factory/CloneQuoteToInvoiceFactory.php @@ -32,7 +32,9 @@ class CloneQuoteToInvoiceFactory // unset($quote_array['public_notes']); unset($quote_array['footer']); unset($quote_array['design_id']); + unset($quote_array['user']); + foreach ($quote_array as $key => $value) { $invoice->{$key} = $value; } diff --git a/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php b/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php index e34918245585..675827b6cada 100644 --- a/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php +++ b/app/Http/Requests/RecurringExpense/StoreRecurringExpenseRequest.php @@ -63,6 +63,10 @@ class StoreRecurringExpenseRequest extends Request if(array_key_exists('color', $input) && is_null($input['color'])) $input['color'] = ''; + if(array_key_exists('foreign_amount', $input) && is_null($input['foreign_amount'])) + $input['foreign_amount'] = 0; + + $this->replace($input); } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index ac8c453ed81d..d75e03f7e6f6 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -209,7 +209,7 @@ class BaseRepository if(!$model->id) $this->new_model = true; - + $model->saveQuietly(); /* Model now persisted, now lets do some child tasks */ diff --git a/app/Services/Invoice/ApplyPaymentAmount.php b/app/Services/Invoice/ApplyPaymentAmount.php index 4a71ae6c85d5..1250bb506c4f 100644 --- a/app/Services/Invoice/ApplyPaymentAmount.php +++ b/app/Services/Invoice/ApplyPaymentAmount.php @@ -58,7 +58,7 @@ class ApplyPaymentAmount extends AbstractService $payment->amount = $this->amount; $payment->applied = min($this->amount, $this->invoice->balance); - $payment->number = $this->getNextPaymentNumber($this->invoice->client); + $payment->number = $this->getNextPaymentNumber($this->invoice->client, $payment); $payment->status_id = Payment::STATUS_COMPLETED; $payment->client_id = $this->invoice->client_id; $payment->transaction_reference = ctrans('texts.manual_entry'); diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 8f3db22f8921..a78ba98b2c80 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -52,7 +52,7 @@ class MarkPaid extends AbstractService $payment->amount = $this->invoice->balance; $payment->applied = $this->invoice->balance; - $payment->number = $this->getNextPaymentNumber($this->invoice->client); + $payment->number = $this->getNextPaymentNumber($this->invoice->client, $payment); $payment->status_id = Payment::STATUS_COMPLETED; $payment->client_id = $this->invoice->client_id; $payment->transaction_reference = ctrans('texts.manual_entry'); diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index b55d9d719940..1a7039c27a58 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -215,7 +215,7 @@ trait GeneratesCounter } - public function getNextRecurringQuoteNumber(Client $client, ?RecurringQuote $recurring_quote) + public function getNextRecurringQuoteNumber(Client $client, $recurring_quote) { $entity_number = $this->getNextEntityNumber(RecurringQuote::class, $client); diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 8afad2a18e9f..1fe76bf7bfe8 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -698,7 +698,7 @@ class PaymentTest extends TestCase $payment->amount = 10; $payment->client_id = $client->id; $payment->date = now(); - $payment->number = $client->getNextPaymentNumber($client); + $payment->number = $client->getNextPaymentNumber($client, $payment); $payment->save(); $data = [ diff --git a/tests/Unit/GeneratesCounterTest.php b/tests/Unit/GeneratesCounterTest.php index ead294b9425b..34205857bdcf 100644 --- a/tests/Unit/GeneratesCounterTest.php +++ b/tests/Unit/GeneratesCounterTest.php @@ -12,6 +12,7 @@ namespace Tests\Unit; use App\DataMapper\ClientSettings; use App\Factory\ClientFactory; +use App\Factory\QuoteFactory; use App\Factory\VendorFactory; use App\Models\Client; use App\Models\Company; @@ -184,24 +185,22 @@ class GeneratesCounterTest extends TestCase public function testQuoteNumberValue() { + $quote = Quote::factory()->create([ + 'user_id' => $this->client->user_id, + 'company_id' => $this->client->company_id, + 'client_id' => $this->client->id + ]); - $quote_number = $this->getNextQuoteNumber($this->client->fresh()); + $quote_number = $this->getNextQuoteNumber($this->client->fresh(), $quote); $this->assertEquals($quote_number, 0002); - // nlog(Quote::all()->pluck('number')); - // $quote_number = $this->getNextQuoteNumber($this->client->fresh()); - - // nlog($this->company->settings->quote_number_counter); - - // nlog(Quote::all()->pluck('number')); - - // $this->assertEquals($quote_number, '0003'); } public function testInvoiceNumberPattern() { + $settings = $this->client->company->settings; $settings->invoice_number_counter = 1; $settings->invoice_number_pattern = '{$year}-{$counter}'; @@ -234,8 +233,15 @@ class GeneratesCounterTest extends TestCase $this->client->save(); $this->client->fresh(); - $quote_number = $this->getNextQuoteNumber($this->client); - $quote_number2 = $this->getNextQuoteNumber($this->client); + $quote = Quote::factory()->create([ + 'user_id' => $this->client->user_id, + 'company_id' => $this->client->company_id, + 'client_id' => $this->client->id + ]); + + + $quote_number = $this->getNextQuoteNumber($this->client, $quote); + $quote_number2 = $this->getNextQuoteNumber($this->client, $quote); $this->assertEquals($quote_number, date('Y').'-0001'); $this->assertEquals($quote_number2, date('Y').'-0002'); @@ -257,8 +263,14 @@ class GeneratesCounterTest extends TestCase $gs->settings = $settings; $gs->save(); - $quote_number = $this->getNextQuoteNumber($this->client); - $quote_number2 = $this->getNextQuoteNumber($this->client); + $quote = Quote::factory()->create([ + 'user_id' => $this->client->user_id, + 'company_id' => $this->client->company_id, + 'client_id' => $this->client->id + ]); + + $quote_number = $this->getNextQuoteNumber($this->client, $quote); + $quote_number2 = $this->getNextQuoteNumber($this->client, $quote); $this->assertEquals($quote_number, date('Y').'-1000'); $this->assertEquals($quote_number2, date('Y').'-1001');