2018-12-02 21:42:06 +11:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
|
*
|
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
|
*/
|
2018-12-02 21:42:06 +11:00
|
|
|
|
|
|
|
|
namespace App\Jobs\Client;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Models\Client;
|
2019-01-25 21:47:23 +11:00
|
|
|
use App\Repositories\ClientContactRepository;
|
2018-12-02 21:42:06 +11:00
|
|
|
use App\Repositories\ClientRepository;
|
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
|
|
class StoreClient
|
|
|
|
|
{
|
|
|
|
|
use Dispatchable;
|
|
|
|
|
|
2019-05-10 16:08:33 +10:00
|
|
|
protected $data;
|
2018-12-02 21:42:06 +11:00
|
|
|
|
|
|
|
|
protected $client;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new job instance.
|
|
|
|
|
*
|
2019-12-07 12:33:49 +01:00
|
|
|
* @param array $data
|
|
|
|
|
* @param Client $client
|
2018-12-02 21:42:06 +11:00
|
|
|
*/
|
|
|
|
|
|
2019-05-10 16:08:33 +10:00
|
|
|
public function __construct(array $data, Client $client)
|
2018-12-02 21:42:06 +11:00
|
|
|
{
|
2019-05-10 16:08:33 +10:00
|
|
|
$this->data = $data;
|
|
|
|
|
|
2018-12-02 21:42:06 +11:00
|
|
|
$this->client = $client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the job.
|
|
|
|
|
*
|
2019-12-07 12:33:49 +01:00
|
|
|
* @param ClientRepository $client_repo
|
|
|
|
|
* @param ClientContactRepository $client_contact_repo
|
|
|
|
|
* @return Client|null
|
2018-12-02 21:42:06 +11:00
|
|
|
*/
|
2019-12-07 12:33:49 +01:00
|
|
|
public function handle(ClientRepository $client_repo, ClientContactRepository $client_contact_repo) : ?Client {
|
|
|
|
|
|
2019-05-10 16:08:33 +10:00
|
|
|
$client = $client_repo->save($this->data, $this->client);
|
2019-01-25 21:47:23 +11:00
|
|
|
|
2019-05-10 16:08:33 +10:00
|
|
|
$contacts = $client_contact_repo->save($data['contacts']), $client);
|
2019-02-17 22:07:58 +11:00
|
|
|
|
|
|
|
|
return $client;
|
2018-12-02 21:42:06 +11:00
|
|
|
}
|
|
|
|
|
}
|