mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-21 00:41:34 +02:00
cf1e65f1c0
* Refactor pivot table accessors * Add select2 for client - country selector * Fixes for client contact update * implement ctrans() function across application * Increase custom fields to 4 across the application * Refactor: remove repos calling other repos, implement 4 custom values across application * include querying the custom values in the client list * Fix null custom value labels * Scaffold for client - show view * Working on Client Show
55 lines
1.1 KiB
PHP
55 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\Client;
|
|
use App\Models\ClientContact;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
class ClientContactRepository extends BaseRepository
|
|
{
|
|
|
|
public function save(array $contacts, Client $client) : void
|
|
{
|
|
|
|
/* Convert array to collection */
|
|
$contacts = collect($contacts);
|
|
|
|
/* Get array of IDs which have been removed from the contacts array and soft delete each contact */
|
|
collect($client->contacts->pluck('id'))->diff($contacts->pluck('id'))->each(function($contact){
|
|
ClientContact::destroy($contact);
|
|
});
|
|
|
|
/* Set first record to primary - always*/
|
|
$contacts = $contacts->sortBy('is_primary');
|
|
|
|
$contacts->first(function($contact){
|
|
$contact['is_primary'] = true;
|
|
});
|
|
|
|
//loop and update/create contacts
|
|
$contacts->each(function ($contact) use ($client){
|
|
|
|
$update_contact = ClientContact::firstOrNew(
|
|
['id' => $contact['id']],
|
|
[
|
|
'client_id' => $client->id,
|
|
'company_id' => $client->company_id,
|
|
'user_id' => auth()->user()->id
|
|
]
|
|
);
|
|
|
|
$update_contact->fill($contact);
|
|
$update_contact->save();
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} |