diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 2cdf4974dec8..15d2e927d09d 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -195,6 +195,8 @@ class BaseModel extends Model // Remove any runs of periods (thanks falstro!) $formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number); + $formatted_number = str_replace(" ", "", $formatted_number); + return $formatted_number; } diff --git a/app/Repositories/ClientContactRepository.php b/app/Repositories/ClientContactRepository.php index 2bc644f8ba4d..6434665ff722 100644 --- a/app/Repositories/ClientContactRepository.php +++ b/app/Repositories/ClientContactRepository.php @@ -22,7 +22,9 @@ use Illuminate\Support\Str; */ class ClientContactRepository extends BaseRepository { - public $is_primary; + private bool $is_primary = true; + + private bool $set_send_email_on_contact = false; public function save(array $data, Client $client) : void { @@ -36,13 +38,20 @@ class ClientContactRepository extends BaseRepository ClientContact::destroy($contact); }); - $this->is_primary = true; + /* Ensure send_email always exists in at least one contact */ + if(!$contacts->contains('send_email', true)) + $this->set_send_email_on_contact = true; /* Set first record to primary - always */ $contacts = $contacts->sortByDesc('is_primary')->map(function ($contact) { $contact['is_primary'] = $this->is_primary; $this->is_primary = false; + if($this->set_send_email_on_contact){ + $contact['send_email'] = true; + $this->set_send_email_on_contact = false; + } + return $contact; }); diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 3cfa82879142..c7ae018be8f0 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -129,7 +129,7 @@ class PaymentRepository extends BaseRepository { //todo optimize this into a single query foreach ($data['invoices'] as $paid_invoice) { - $invoice = Invoice::whereId($paid_invoice['invoice_id'])->first(); + $invoice = Invoice::withTrashed()->whereId($paid_invoice['invoice_id'])->first(); if ($invoice) { $invoice = $invoice->service() diff --git a/resources/views/portal/ninja2020/components/general/sidebar/header.blade.php b/resources/views/portal/ninja2020/components/general/sidebar/header.blade.php index 95e5b31a6075..639f95cf4667 100644 --- a/resources/views/portal/ninja2020/components/general/sidebar/header.blade.php +++ b/resources/views/portal/ninja2020/components/general/sidebar/header.blade.php @@ -25,8 +25,8 @@ @foreach($multiple_contacts as $contact) {{ $contact->company->present()->name() }} - - {{ $contact->client->present()->name()}} + class="block px-4 py-2 text-sm leading-5 text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900">{{ $contact->client->present()->name()}} - {{ $contact->company->present()->name() }} + @endforeach diff --git a/tests/Unit/CollectionMergingTest.php b/tests/Unit/CollectionMergingTest.php index f223011a12c2..57ab951ad9d0 100644 --- a/tests/Unit/CollectionMergingTest.php +++ b/tests/Unit/CollectionMergingTest.php @@ -10,6 +10,7 @@ */ namespace Tests\Unit; +use App\Factory\ClientContactFactory; use App\Factory\InvoiceItemFactory; use App\Utils\Traits\UserSessionAttributes; use Illuminate\Support\Facades\Session; @@ -77,4 +78,41 @@ class CollectionMergingTest extends TestCase $this->assertTrue(collect($items)->contains('type_id', 3)); } + + public function testClientContactSendEmailExists() + { + $new_collection = collect(); + + $cc = ClientContactFactory::create(1,1); + $cc->send_email = true; + + $new_collection->push($cc); + + $cc_false = ClientContactFactory::create(1,1); + $cc_false->send_email = false; + + $new_collection->push($cc_false); + + $this->assertTrue($new_collection->contains('send_email', true)); + + } + + public function testClientContactSendEmailDoesNotExists() + { + $new_collection = collect(); + + $cc = ClientContactFactory::create(1,1); + $cc->send_email = false; + + $new_collection->push($cc); + + $cc_false = ClientContactFactory::create(1,1); + $cc_false->send_email = false; + + $new_collection->push($cc_false); + + $this->assertFalse($new_collection->contains('send_email', true)); + + } + }