diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index fe34fcacc87a..120d56885386 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -67,16 +67,17 @@ class InvoiceRepository extends BaseRepository { if (isset($data['invitations'])) { $invitations = collect($data['invitations']); - /* Get array of Keyss which have been removed from the invitations array and soft delete each invitation */ + /* Get array of Keys which have been removed from the invitations array and soft delete each invitation */ collect($invoice->invitations->pluck('key'))->diff($invitations->pluck('key'))->each(function ($invitation) { - InvoiceInvitation::destroy($invitation); + InvoiceInvitation::whereRaw("BINARY `key`= ?", [$invitation])->delete(); }); foreach ($data['invitations'] as $invitation) { $inv = false; if (array_key_exists('key', $invitation)) { - $inv = InvoiceInvitation::whereKey($invitation['key'])->first(); + // $inv = InvoiceInvitation::whereKey($invitation['key'])->first(); + $inv = InvoiceInvitation::whereRaw("BINARY `key`= ?", [$invitation['key']])->first(); } if (!$inv) { diff --git a/app/Transformers/InvoiceInvitationTransformer.php b/app/Transformers/InvoiceInvitationTransformer.php index c1c302838cbf..f347344c9da8 100644 --- a/app/Transformers/InvoiceInvitationTransformer.php +++ b/app/Transformers/InvoiceInvitationTransformer.php @@ -11,24 +11,23 @@ namespace App\Transformers; -use App\Models\Invoice; use App\Models\InvoiceInvitation; use App\Utils\Traits\MakesHash; -class InvoiceInvitationTransformer extends EntityTransformer -{ - use MakesHash; +class InvoiceInvitationTransformer extends EntityTransformer { + use MakesHash; - public function transform(InvoiceInvitation $invitation) - { - return [ - 'id' => $this->encodePrimaryKey($invitation->id), - 'client_contact_id' => $this->encodePrimaryKey($invitation->client_contact_id), - 'key' => $invitation->key, - 'link' => $invitation->getLink() ?: '', - 'sent_date' => $invitation->sent_date ?: '', - 'viewed_date' => $invitation->viewed_date ?: '', - 'opened_date' => $invitation->opened_date ?: '', - ]; - } + public function transform(InvoiceInvitation $invitation) { + return [ + 'id' => $this->encodePrimaryKey($invitation->id), + 'client_contact_id' => $this->encodePrimaryKey($invitation->client_contact_id), + 'key' => $invitation->key, + 'link' => $invitation->getLink()?:'', + 'sent_date' => $invitation->sent_date?:'', + 'viewed_date' => $invitation->viewed_date?:'', + 'opened_date' => $invitation->opened_date?:'', + 'updated_at' => (int) $invitation->updated_at, + 'archived_at' => (int) $invitation->deleted_at, + ]; + } }